win32/coil/Mutex.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_MUTEX_H
21 #define COIL_MUTEX_H
22 
23 #include <windows.h>
24 
25 namespace coil
26 {
27  typedef HANDLE pthread_mutex_t;
28 
42  class Mutex
43  {
44  public:
64  Mutex(const char * const name = 0)
65  {
66  SECURITY_DESCRIPTOR sd_buffer;
67  ::InitializeSecurityDescriptor(&sd_buffer,
68  SECURITY_DESCRIPTOR_REVISION);
69  ::SetSecurityDescriptorDacl (&sd_buffer, TRUE, 0, FALSE);
70  m_Security_attr.nLength = sizeof(SECURITY_ATTRIBUTES);
71  m_Security_attr.lpSecurityDescriptor = &sd_buffer;
72  m_Security_attr.bInheritHandle = TRUE;
73  mutex_ = ::CreateMutexA( &m_Security_attr,
74  FALSE,
75  name );
76 
77 
78  }
79 
96  {
97  ::CloseHandle(mutex_);
98 
99  }
100 
116  inline void lock()
117  {
118  ::WaitForSingleObject(mutex_,INFINITE);
119  }
120 
136  inline bool trylock()
137  {
138  unsigned long dwret;
139  dwret = ::WaitForSingleObject(mutex_,0);
140  switch(dwret)
141  {
142  case WAIT_ABANDONED:
143  return true;
144  break;
145  case WAIT_OBJECT_0:
146  return false;
147  case WAIT_TIMEOUT:
148  return true;
149  default:
150  return true;
151  }
152  }
153 
169  inline void unlock()
170  {
171  ::ReleaseMutex(mutex_);
172  }
173  HANDLE mutex_;
174 
175  private:
176  SECURITY_ATTRIBUTES m_Security_attr;
177 
178  Mutex(const Mutex&);
179  Mutex& operator=(const Mutex &);
180  };
181 };
182 #endif // COIL_MUTEX_H
ACE_thread_mutex_t mutex_
void lock()
Mutual exclusion lock.
~Mutex()
Destructor.
void unlock()
Mutual exclusion unlock.
bool trylock()
Mutual exclusion non-blocking lock.
SECURITY_ATTRIBUTES m_Security_attr
Mutex(const char *const name=0)
Constructor.
HANDLE pthread_mutex_t
Mutex(const char *naem=0)
Mutex & operator=(const Mutex &)
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:53