diff options
author | David Robillard <d@drobilla.net> | 2012-01-31 03:20:19 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-01-31 03:20:19 +0000 |
commit | 59af1e8d99d33f438b3b769a060b7d7ce8cde61f (patch) | |
tree | 7d8ea67407f1f1aa0a6b010ddbe849c22f8f5c44 | |
parent | 17936e0b03b807a349ab86ffed10222c17aa30df (diff) | |
download | zix-59af1e8d99d33f438b3b769a060b7d7ce8cde61f.tar.gz zix-59af1e8d99d33f438b3b769a060b7d7ce8cde61f.tar.bz2 zix-59af1e8d99d33f438b3b769a060b7d7ce8cde61f.zip |
Use Mach semaphores instead of ancient (and now deprecated) Mac semaphore API.
git-svn-id: http://svn.drobilla.net/zix/trunk@48 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
-rw-r--r-- | zix/sem.h | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -20,8 +20,7 @@ #include <stdbool.h> #ifdef __APPLE__ -# include <limits.h> -# include <CoreServices/CoreServices.h> +# include <mach/mach.h> #else # include <semaphore.h> #endif @@ -95,38 +94,39 @@ zix_sem_try_wait(ZixSem* sem); #ifdef __APPLE__ struct ZixSemImpl { - MPSemaphoreID sem; + semaphore_t sem; }; static inline ZixStatus zix_sem_init(ZixSem* sem, unsigned initial) { - return MPCreateSemaphore(UINT_MAX, initial, &sem->sem) + return semaphore_create(mach_task_self(), &sem->sem, SYNC_POLICY_FIFO, 0) ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR; } static inline void zix_sem_destroy(ZixSem* sem) { - MPDeleteSemaphore(sem->sem); + semaphore_destroy(mach_task_self(), sem->sem); } static inline void zix_sem_post(ZixSem* sem) { - MPSignalSemaphore(sem->sem); + semaphore_signal(sem->sem); } static inline void zix_sem_wait(ZixSem* sem) { - MPWaitOnSemaphore(sem->sem, kDurationForever); + semaphore_wait(sem->sem); } static inline bool zix_sem_try_wait(ZixSem* sem) { - return MPWaitOnSemaphore(sem->sem, kDurationImmediate) == noErr; + const mach_timespec_t zero = { 0, 0 }; + return semaphore_timedwait(sem->sem, zero) == KERN_SUCCESS; } #else /* !defined(__APPLE__) */ |