25 #ifndef STTCLCX11SEMAPHORE_H_
26 #define STTCLCX11SEMAPHORE_H_
28 #if defined(STTCL_CX11_THREADS) or defined(STTCL_CX11_IMPL)
30 #include <condition_variable>
33 #include "../include/SttclTime.h"
42 class Cx11SemaphoreSurrogate {
45 std::condition_variable v;
48 Cx11SemaphoreSurrogate(
int v): mV(v){}
49 void post(
int count=1){
50 std::unique_lock<std::mutex> lock(mMutex);
52 if (mV > 0) v.notify_all();
54 void wait(
int count = 1){
55 std::unique_lock<std::mutex> lock(mMutex);
61 bool try_wait(
int count = 1, T duration = T()){
62 std::unique_lock<std::mutex> lock(mMutex);
66 if (v.wait_for(lock,duration) == std::cv_status::timeout)
78 class SttclCx11Semaphore
81 typedef Cx11SemaphoreSurrogate NativeSemaphoreType;
82 SttclCx11Semaphore(
unsigned int initialCount);
83 virtual ~SttclCx11Semaphore();
86 bool try_wait(
const TimeDuration<>& timeout);
90 NativeSemaphoreType semaphore;