mirror of
https://github.com/upa/mscp.git
synced 2026-02-15 09:44:43 +08:00
add sem_create(), wrappign sem_init() for linux and sem_open() for macOS
This commit is contained in:
@@ -2,13 +2,20 @@
|
||||
#define _PLATFORM_H_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef PSEMNAMLEN /* defined in macOS, but not in Linux */
|
||||
#define PSEMNAMLEN 31
|
||||
#endif
|
||||
#include <semaphore.h>
|
||||
|
||||
int nr_cpus(void);
|
||||
int set_thread_affinity(pthread_t tid, int core);
|
||||
int get_random(int max);
|
||||
|
||||
/*
|
||||
* macOS does not support sem_init(). macOS (seems to) releases the
|
||||
* named semaphore when associated mscp process finished. In linux,
|
||||
* program (seems to) need to release named semaphore in /dev/shm by
|
||||
* sem_unlink() explicitly. So, using sem_init() (unnamed semaphore)
|
||||
* in linux and using sem_open() (named semaphore) in macOS without
|
||||
* sem_unlink() are reasonable (?).
|
||||
*/
|
||||
sem_t *sem_create(int value);
|
||||
int sem_release(sem_t *sem);
|
||||
|
||||
#endif /* _PLATFORM_H_ */
|
||||
|
||||
Reference in New Issue
Block a user