OpenRTM-aist  1.2.1
Mutex.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_MUTEX_H
21 #define COIL_MUTEX_H
22 
23 #include <pthread.h>
24 
25 namespace coil
26 {
40  class Mutex
41  {
42  public:
62  Mutex(const char * const name = 0)
63  {
64  ::pthread_mutex_init(&mutex_, 0);
65  }
66 
83  {
84  ::pthread_mutex_destroy(&mutex_);
85  }
86 
102  inline void lock()
103  {
104  ::pthread_mutex_lock(&mutex_);
105  }
106 
122  inline bool trylock()
123  {
124  return ::pthread_mutex_trylock(&mutex_);
125  }
126 
142  inline void unlock()
143  {
144  ::pthread_mutex_unlock(&mutex_);
145  }
146 
158  pthread_mutex_t mutex_;
159 
160  private:
161  Mutex(const Mutex&);
162  Mutex& operator=(const Mutex &);
163  };
164 };
165 #endif // COIL_MUTEX_H
Mutex class.
Definition: Mutex.h:40
void lock()
Mutual exclusion lock.
Definition: Mutex.h:102
~Mutex()
Destructor.
Definition: Mutex.h:82
void unlock()
Mutual exclusion unlock.
Definition: Mutex.h:142
bool trylock()
Mutual exclusion non-blocking lock.
Definition: Mutex.h:122
Mutex(const char *const name=0)
Constructor.
Definition: Mutex.h:62
pthread_mutex_t mutex_
Mutual exclusion object.
Definition: Mutex.h:158
Common Object Interface Layer.
Definition: Affinity.h:28