posix/coil/Condition.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_CONDITION_H
21 #define COIL_CONDITION_H
22 
23 #include <pthread.h>
24 #include <algorithm>
25 #include <ctime>
26 #include <sys/time.h>
27 
28 namespace coil
29 {
43  template <class M>
44  class Condition
45  {
46  public:
47 
63  Condition(M& mutex)
64  : m_mutex(mutex)
65  {
67  }
68 
85  {
86  ::pthread_cond_destroy(&m_cond);
87  }
88 
104  inline void signal()
105  {
107  }
108 
124  inline void broadcast()
125  {
127  }
128 
148  bool wait()
149  {
150  return 0 == ::pthread_cond_wait(&m_cond, &m_mutex.mutex_);
151  }
152 
178  bool wait(long second, long nano_second = 0)
179  {
180  struct timeval tv;
181  timespec abstime;
182 
183  ::gettimeofday(&tv, NULL);
184  abstime.tv_sec = tv.tv_sec + second;
185  abstime.tv_nsec = tv.tv_usec * 1000 + nano_second;
186  if (abstime.tv_nsec >= 1000000000) {
187  abstime.tv_nsec -= 1000000000;
188  abstime.tv_sec ++;
189  }
190  return 0 == ::pthread_cond_timedwait(&m_cond, &m_mutex.mutex_, &abstime);
191  }
192 
193  private:
194  Condition(const M&);
195  Condition& operator=(const M &);
198  };
199 };
200 #endif // COIL_CONDITION_H
int pthread_cond_broadcast(pthread_cond_t *cv)
Resume of all the thread practice.
int pthread_cond_wait(coil::pthread_cond_t *cv, coil::Mutex *external_mutex, DWORD aMilliSecond)
Wait of the thread practice.
ACE_thread_mutex_t mutex_
~Condition()
Destructor.
Condition(M &mutex)
Constructor.
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
Condition & operator=(const Mutex &)
void broadcast()
Resume of all the thread practice.
Condition(Mutex &mutex)
int pthread_cond_signal(pthread_cond_t *cv)
Resume of the thread practice.
static int pthread_cond_init(pthread_cond_t *cv)
bool wait(long second, long nano_second=0)
Thread practice wait of set time.
pthread_cond_t m_cond
void signal()
Resume of the thread practice.
Common Object Interface Layer.
bool wait()
Wait of the thread practice.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:42