sttcl  v0.9c
STTCL C++ template state machine framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SttclSemaphore.h
Go to the documentation of this file.
1 
25 #ifndef STTCLSEMAPHORE_H_
26 #define STTCLSEMAPHORE_H_
27 
28 #include "SttclTime.h"
29 
30 #ifndef STTCL_DEFAULT_SEMAPHOREIMPL
31 #if defined(STTCL_POSIX_SEMAPHORE) or defined(STTCL_POSIX_IMPL)
32 #include "../PosixThreads/SttclPosixSemaphore.h"
33 #define STTCL_DEFAULT_SEMAPHOREIMPL sttcl::internal::posix_impl::SttclPosixSemaphore
34 #elif defined(STTCL_BOOST_SEMAPHORE) or defined(STTCL_BOOST_IMPL)
35 #include "../BoostThreads/SttclBoostSemaphore.h"
36 #define STTCL_DEFAULT_SEMAPHOREIMPL sttcl::internal::boost_impl::SttclBoostSemaphore
37 #elif defined(STTCL_CX11_SEMAPHORE) or defined(STTCL_CX11_IMPL)
38 #include "../C++11Threads/SttclCx11Semaphore.h"
39 #define STTCL_DEFAULT_SEMAPHOREIMPL sttcl::internal::cx11_impl::SttclCx11Semaphore
40 #endif
41 
42 #ifndef STTCL_DEFAULT_SEMAPHOREIMPL
43 #error "You need to define a default semaphore implementation for sttcl"
44 #endif
45 #endif
46 
47 namespace sttcl
48 {
49 
50 namespace internal
51 {
58 template
59 < class Impl = STTCL_DEFAULT_SEMAPHOREIMPL
60 , class TimeDurationType = TimeDuration<STTCL_DEFAULT_TIMEDURATIONIMPL>
61 >
63 : public Impl
64 {
65 public:
70  SttclSemaphore(unsigned int initialCount = 0) : Impl(initialCount) {}
75 
79  void wait()
80  {
81  static_cast<Impl*>(this)->wait();
82  }
83 
90  bool try_wait(const TimeDurationType& timeout = TimeDurationType::Zero)
91  {
92  return static_cast<Impl*>(this)->try_wait(timeout);
93  }
94 
98  void post()
99  {
100  static_cast<Impl*>(this)->post();
101  }
102 };
103 
104 }
105 }
106 
107 #endif /* STTCLSEMAPHORE_H_ */