parent
1804062e26
commit
a6192b1ad2
@ -0,0 +1,40 @@
|
||||
#ifdef __APPLE__
|
||||
|
||||
// OS X
|
||||
#include <semaphore.h>
|
||||
|
||||
typedef dispatch_semaphore_t bindings_sem_t;
|
||||
|
||||
NAN_INLINE static int semaphore_init (dispatch_semaphore_t *sem) {
|
||||
*sem = dispatch_semaphore_create(0);
|
||||
return *sem == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_wait (dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_signal (dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_signal(*sem);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Linux and whatnot
|
||||
#include <semaphore.h>
|
||||
|
||||
typedef sem_t bindings_sem_t;
|
||||
|
||||
NAN_INLINE static int semaphore_init (sem_t *sem) {
|
||||
return sem_init(sem, 0, 0);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_wait (sem_t *sem) {
|
||||
sem_wait(sem);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_signal (sem_t *sem) {
|
||||
sem_post(sem);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in new issue