! 4 space instead of tab & remove global std
[scx.git] / include / SemVar.hpp
blob100abd0e568ac652f9b2c8d4f6a40f467e961fa9
1 #ifndef SCX_SEM_VAR_HPP
2 #define SCX_SEM_VAR_HPP
4 #include <semaphore.h>
6 namespace scx {
8 class SemVar
10 public:
11 explicit SemVar(int pshared, int value)
13 sem_init(&m_Sem, pshared, value);
16 ~SemVar()
18 sem_destroy(&m_Sem);
21 int Post()
23 return sem_post(&m_Sem);
26 int TryWait()
28 return sem_trywait(&m_Sem);
31 int Wait()
33 return sem_wait(&m_Sem);
36 void TimeWait()
38 //return sem_timewait(&m_Sem, timeout);
42 int GetValue()
44 int sval = 0;
45 sem_getvalue(&m_Sem, &sval);
46 return sval;
49 private:
50 sem_t m_Sem;
55 #endif