18 #ifndef RAUL_SEMAPHORE_HPP
19 #define RAUL_SEMAPHORE_HPP
21 #include <semaphore.h>
22 #include <boost/utility.hpp>
41 inline Semaphore(
unsigned int initial) { sem_init(&_sem, 0, initial); }
43 inline ~
Semaphore() { sem_destroy(&_sem); }
45 inline void reset(
unsigned int initial) {
47 sem_init(&_sem, 0, initial);
50 inline bool has_waiter() {
52 sem_getvalue(&_sem, &val);
60 inline void post() { sem_post(&_sem); }
69 inline void wait() {
while (sem_wait(&_sem) != 0) ; }
77 inline bool try_wait() {
return (sem_trywait(&_sem) == 0); }
86 #endif // RAUL_SEMAPHORE_HPP
Trivial wrapper around POSIX semaphores (zero memory overhead).
Definition: Semaphore.hpp:39
bool try_wait()
Non-blocking version of wait().
Definition: Semaphore.hpp:77
void wait()
Wait until count is > 0, then decrement.
Definition: Semaphore.hpp:69
void post()
Increment (and signal any waiters).
Definition: Semaphore.hpp:60