MacOS X doesn't implement unnamed POSIX semaphores even though their libc

defines the functions. Use Mach semaphores instead.
This commit is contained in:
gbeauche 2005-05-14 17:32:55 +00:00
parent 85db30f78d
commit 1b53603138

View File

@ -7,6 +7,19 @@
extern "C" {
#endif /* c_plusplus || __cplusplus */
/* MacOS X doesn't implement unnamed POSIX semaphores, event though
the libc defines them! */
#if (defined(__MACH__) && defined(__APPLE__))
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/semaphore.h>
#define sem_t semaphore_t
#define sem_init(SEM,UNUSED,VALUE) semaphore_create(current_task(), (SEM), SYNC_POLICY_FIFO, (VALUE))
#define sem_destroy(SEM) semaphore_destroy(current_task(), *(SEM))
#define sem_wait(SEM) semaphore_wait(*(SEM))
#define sem_post(SEM) semaphore_signal(*(SEM))
#else
typedef struct psem {
pthread_mutex_t sem_lock;
int sem_value;
@ -22,6 +35,7 @@ int sem_wait(sem_t* sem);
int sem_trywait(sem_t* sem);
int sem_post(sem_t* sem);
int sem_getvalue(sem_t* sem, int* sval);
#endif
#if defined(c_plusplus) || defined(__cplusplus)
};