ace/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 <coil/config_coil.h>
24 #if defined (WIN32)
25 #pragma warning( disable : 4244 )
26 #pragma warning( disable : 4312 )
27 #endif
28 #include <ace/OS_NS_Thread.h>
29 #if defined (WIN32)
30 #pragma warning( default : 4244 )
31 #pragma warning( default : 4312 )
32 #endif
33 #include <coil/TimeValue.h>
34 #include <coil/Time.h>
35 
36 namespace coil
37 {
38  template <class Mutex>
39  class Condition
40  {
41  public:
42  Condition(Mutex& mutex)
43  : m_mutex(mutex)
44  {
45  ACE_OS::cond_init(&m_cond, 0);
46  }
47 
49  {
50  ACE_OS::cond_destroy(&this->m_cond);
51  }
52 
53  inline void signal()
54  {
55  m_mutex.trylock();
56  ACE_OS::cond_signal(&m_cond);
57  }
58 
59  inline void broadcast()
60  {
61  m_mutex.trylock();
62  ACE_OS::cond_broadcast(&m_cond);
63  }
64 
65  bool wait()
66  {
67  m_mutex.trylock();
68  return 0 == ACE_OS::cond_wait(&m_cond, &m_mutex.mutex_);
69  }
70 
71  bool wait(long second, long nano_second = 0)
72  {
73  m_mutex.trylock();
75  coil::TimeValue abst(second, nano_second * 1000);
76  abst += now;
77  ACE_Time_Value abstime(abst.sec(), abst.usec());
78  return 0 == ACE_OS::cond_timedwait(m_cond, &m_mutex.mutex_, &abstime);
79  }
80 
81  private:
82  Condition(const Mutex&);
83  Condition& operator=(const Mutex &);
84  ACE_cond_t m_cond;
86  };
87 };
88 #endif // COIL_CONDITION_H
ACE_thread_mutex_t mutex_
long int sec() const
Get value of second time scale.
Definition: TimeValue.h:110
TimeValue class.
Definition: TimeValue.h:40
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
Condition & operator=(const Mutex &)
bool trylock()
Condition(Mutex &mutex)
long int usec() const
Get value of micro second time scale.
Definition: TimeValue.h:131
bool wait(long second, long nano_second=0)
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:57