logog
logger optimized for games
mutex.hpp
Go to the documentation of this file.
1 
5 #ifndef __LOGOG_MUTEX_HPP__
6 #define __LOGOG_MUTEX_HPP__
7 
8 #ifdef LOGOG_FLAVOR_POSIX
9 #include <pthread.h>
10 #endif
11 
12 namespace logog
13 {
14 
16 #ifndef LOGOG_MUTEX
17 
18 #ifdef LOGOG_FLAVOR_WINDOWS
19 #define LOGOG_MUTEX(x) CRITICAL_SECTION (x);
20 #define LOGOG_MUTEX_INIT(x) InitializeCriticalSection (x)
21 #define LOGOG_MUTEX_DELETE(x) DeleteCriticalSection (x)
22 #define LOGOG_MUTEX_LOCK(x) EnterCriticalSection (x)
23 #define LOGOG_MUTEX_UNLOCK(x) LeaveCriticalSection (x)
24 #define LOGOG_MUTEX_CTOR(x)
25 #endif // LOGOG_FLAVOR_WINDOWS
26 
27 #ifdef LOGOG_FLAVOR_POSIX
28 #define LOGOG_MUTEX(x) pthread_mutex_t (x);
29 #define LOGOG_MUTEX_INIT(x) pthread_mutex_init(x, 0)
30 #define LOGOG_MUTEX_DELETE(x) pthread_mutex_destroy (x)
31 #define LOGOG_MUTEX_LOCK(x) pthread_mutex_lock (x)
32 #define LOGOG_MUTEX_UNLOCK(x) pthread_mutex_unlock (x)
33 #define LOGOG_MUTEX_CTOR(x)
34 #endif // LOGOG_FLAVOR_POSIX
35 #endif // LOGOG_MUTEX
36 
37 #ifndef LOGOG_MUTEX
38 #error You need to define mutex macros for your platform; please see mutex.hpp
39 #endif
40 
42 
48 class Mutex : public Object
49 {
50 public:
51  Mutex();
52  ~Mutex();
54  void MutexLock();
56  void MutexUnlock();
57 
58 protected:
59  Mutex(const Mutex &);
60  Mutex & operator = (const Mutex &);
61 
62  LOGOG_MUTEX( m_Mutex )
63 };
64 
68 class ScopedLock : public Object
69 {
70 public :
74  ScopedLock( Mutex &mutex );
75  ~ScopedLock();
76 protected:
79 
80 private:
81  /* no default constructor */
82  ScopedLock();
83  /* no copy constructor */
84  ScopedLock( const ScopedLock &other );
85 };
86 
87 #ifdef LOGOG_LEAK_DETECTION
89 extern void LockAllocationsMutex();
90 extern void UnlockAllocationsMutex();
91 #endif // LOGOG_LEAK_DETECTION
92 
93 extern Mutex &GetStringSearchMutex();
94 extern void DestroyStringSearchMutex();
95 
96 }
97 
98 #endif // __LOGOG_MUTEX_HPP_
[Thread]
Definition: api.hpp:8
void MutexLock()
Mutex & operator=(const Mutex &)
[Mutex]
Definition: mutex.hpp:48
void UnlockAllocationsMutex()
Mutex & GetStringSearchMutex()
Mutex * m_pMutex
Definition: mutex.hpp:78
Mutex s_AllocationsMutex
Definition: mutex.hpp:68
void MutexUnlock()
Definition: object.hpp:47
void LockAllocationsMutex()
void DestroyStringSearchMutex()