28 #include "memory/allocation.hpp" 29 30 #include <semaphore.h> 31 32 class PosixSemaphore : public CHeapObj<mtInternal> { 33 sem_t _semaphore; 34 35 // Prevent copying and assignment. 36 PosixSemaphore(const PosixSemaphore&); 37 PosixSemaphore& operator=(const PosixSemaphore&); 38 39 public: 40 PosixSemaphore(uint value = 0); 41 ~PosixSemaphore(); 42 43 void signal(uint count = 1); 44 45 void wait(); 46 47 bool trywait(); 48 bool timedwait(unsigned int sec, int nsec) { 49 return timedwait(create_timespec(sec, nsec)); 50 } 51 52 private: 53 bool timedwait(struct timespec ts); 54 55 // OS specific implementation to create a timespec suitable for semaphores. 56 struct timespec create_timespec(unsigned int set, int nsec); 57 }; 58 59 typedef PosixSemaphore SemaphoreImpl; 60 61 #endif // OS_POSIX_VM_SEMAPHORE_POSIX_HPP | 28 #include "memory/allocation.hpp" 29 30 #include <semaphore.h> 31 32 class PosixSemaphore : public CHeapObj<mtInternal> { 33 sem_t _semaphore; 34 35 // Prevent copying and assignment. 36 PosixSemaphore(const PosixSemaphore&); 37 PosixSemaphore& operator=(const PosixSemaphore&); 38 39 public: 40 PosixSemaphore(uint value = 0); 41 ~PosixSemaphore(); 42 43 void signal(uint count = 1); 44 45 void wait(); 46 47 bool trywait(); 48 bool timedwait(struct timespec ts); 49 }; 50 51 typedef PosixSemaphore SemaphoreImpl; 52 53 #endif // OS_POSIX_VM_SEMAPHORE_POSIX_HPP |