18 #ifndef RAUL_SEMAPHORE_HPP 19 #define RAUL_SEMAPHORE_HPP 23 #include <CoreServices/CoreServices.h> 25 #include <semaphore.h> 28 #include <boost/utility.hpp> 41 MPCreateSemaphore(UINT_MAX, initial, &_sem);
43 sem_init(&_sem, 0, initial);
49 MPDeleteSemaphore(_sem);
59 inline void reset(
unsigned int initial) {
61 MPDeleteSemaphore(_sem);
62 MPCreateSemaphore(UINT_MAX, initial, &_sem);
65 sem_init(&_sem, 0, initial);
75 MPSignalSemaphore(_sem);
87 MPWaitOnSemaphore(_sem, kDurationForever);
93 while (sem_wait(&_sem) != 0) {}
105 return MPWaitOnSemaphore(_sem, kDurationImmediate) == noErr;
107 return (sem_trywait(&_sem) == 0);
122 #endif // RAUL_SEMAPHORE_HPP Counting semaphore.
Definition: Semaphore.hpp:37
bool try_wait()
Non-blocking version of wait().
Definition: Semaphore.hpp:103
void wait()
Wait until count is > 0, then decrement.
Definition: Semaphore.hpp:85
void post()
Increment (and signal any waiters).
Definition: Semaphore.hpp:73
void reset(unsigned int initial)
Destroy and reset the semaphore to an initial value.
Definition: Semaphore.hpp:59