commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MutexImpl.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014 Raphael David / CANTOR
3 //
4 // this file contains Mutex::Impl declaration.
5 // implementation is OS specific and can be found in CriticalSection-<os>.cpp
6 
7 #ifndef CMR_MUTEX_IMPL_INCLUDED
8 #define CMR_MUTEX_IMPL_INCLUDED
9 
10 #include "commore/Commore.h"
11 #include "commore/Path.h"
12 #include "commore/Time.h"
13 
14 namespace commore
15 {
16  //
17  // System dependent Mutex
18  //
19 #ifdef WIN32
20 
21  class Mutex::Impl
22  {
23  public:
24  Impl(const char* name, bool create);
25  ~Impl();
26 
27  public:
28  bool lock();
29  bool try_lock();
30  bool lock(TimePeriod timeout);
31  bool unlock();
32  bool is_ok();
33 
34  private:
35  void* hMutex_;
36  AString name_;
37  bool create_;
38  };
39 
40 #else
41 
42 #include <sys/types.h>
43 
45  {
46  public:
47  Impl(const char* name, bool create);
48  ~Impl();
49  bool lock();
50  bool try_lock();
51  bool lock(TimePeriod timeout);
52  bool unlock();
53  bool is_ok();
54 
55  private:
56  Path tmp_file_;
57  key_t key_;
58  int shr_sem_;
59  AString name_;
60  bool create_;
61  bool ok_;
62  };
63 
64 #endif
65 
66 };
67 
68 #endif
Definition: MutexImpl.h:44
Definition: AString.h:39
Definition: Time.h:21
bool unlock()
Definition: CriticalSection-linux.cpp:293
bool create(const AChar *name)
Definition: CriticalSection.cpp:27
bool is_ok()
Definition: CriticalSection-linux.cpp:322
Impl(const char *name, bool create)
Definition: CriticalSection-linux.cpp:107
bool try_lock()
Definition: CriticalSection-linux.cpp:249
bool lock()
Definition: CriticalSection-linux.cpp:220
Definition: Path.h:19
~Impl()
Definition: CriticalSection-linux.cpp:205