Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mutex.h
Go to the documentation of this file.
1 
18 #ifndef ION_PORT_MUTEX_H_
19 #define ION_PORT_MUTEX_H_
20 
21 #if defined(ION_PLATFORM_WINDOWS)
22 # include <windows.h>
23 #else
24 # include <pthread.h>
25 #endif
26 
27 #include "base/macros.h"
28 
29 namespace ion {
30 namespace port {
31 
34 class ION_API Mutex {
35  public:
36  Mutex();
37  ~Mutex();
38 
40  bool IsLocked();
44  void Lock();
47  bool TryLock();
51  void Unlock();
52 
53  private:
55 #if defined(ION_PLATFORM_WINDOWS)
56  CRITICAL_SECTION critical_section_;
57  LONG blockers_;
58  HANDLE event_;
59  DWORD thread_id_;
60 #elif defined(ION_PLATFORM_ASMJS)
61  bool locked_;
62 #else
63  pthread_mutex_t pthread_mutex_;
64 #endif
65 
66  DISALLOW_COPY_AND_ASSIGN(Mutex);
67 };
68 
69 } // namespace port
70 } // namespace ion
71 
72 #endif // ION_PORT_MUTEX_H_
A Mutex is used to ensure that only one thread or process can access a block of code at one time...
Definition: mutex.h:34