dcrud  0.0.0
Distributed data and services
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Mutex.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <os/Mutex.h>
4 
5 namespace os {
6 
7  class Mutex {
8  private:
9 
10  osMutex _mutex;
11 
12  Mutex( const Mutex & );
13  Mutex & operator = ( const Mutex & );
14 
15  public:
16 
17  Mutex() {
18  osMutex_new( &_mutex );
19  }
20 
21  ~ Mutex() {
22  osMutex_delete( &_mutex );
23  }
24 
25  public:
26 
27  int take() {
28  return osMutex_take( _mutex );
29  }
30 
31  int release() {
32  return osMutex_release( _mutex );
33  }
34  };
35 
36  class Synchronized {
37  public:
38 
39  Synchronized( Mutex & mutex ) :
40  _mutex( mutex )
41  {
42  _mutex.take();
43  }
44 
46  _mutex.release();
47  }
48 
49  private:
50 
51  Mutex & _mutex;
52 
53  private:
54  Synchronized( const Synchronized & );
55  Synchronized & operator = ( const Synchronized & );
56  };
57 }
~Mutex()
Definition: Mutex.hpp:21
int take()
Definition: Mutex.hpp:27
int release()
Definition: Mutex.hpp:31
Synchronized(Mutex &mutex)
Definition: Mutex.hpp:39
Mutex()
Definition: Mutex.hpp:17