diff options
author | Ryo Nakamura <upa@haeena.net> | 2023-03-15 23:54:57 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2023-03-15 23:54:57 +0900 |
commit | ae4b848ba00d7fa49de4ea619e9e90e3eaa68354 (patch) | |
tree | 938bb3edc7f1afa6c107b6aee2970cb2f7abaae6 /src/platform.h | |
parent | 3902fb584a25e607061d739af030660e789c2c6a (diff) |
add sem_create(), wrappign sem_init() for linux and sem_open() for macOS
Diffstat (limited to 'src/platform.h')
-rw-r--r-- | src/platform.h | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/platform.h b/src/platform.h index b4fb1b1..4905db0 100644 --- a/src/platform.h +++ b/src/platform.h @@ -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_ */ |