missing project/build files
[client-tools.git] / src / external / 3rd / library / platform / utils / Base / linux / Mutex.h
blobdd56e3fccec4f25e42c3204b82fe7ce5d3be7abd
1 ////////////////////////////////////////
2 // Mutex.h
3 //
4 // Purpose:
5 // 1. Declair the CMutex class that encapsulates the functionality of a
6 // mutually-exclusive device.
7 //
8 // Revisions:
9 // 07/10/2001 Created
12 #ifndef BASE_LINUX_MUTEX_H
13 #define BASE_LINUX_MUTEX_H
15 #if !defined(_REENTRANT)
16 # pragma message( "Excluding Base::CMutex - requires multi-threaded compile. (_REENTRANT)" )
17 #else
20 #include "Platform.h"
22 #ifdef EXTERNAL_DISTRO
23 namespace NAMESPACE
26 #endif
27 namespace Base
30 ////////////////////////////////////////
31 // Class:
32 // CMutex
34 // Purpose:
35 // Encapsulates the functionality of a mutually-exclusive device.
36 // This class is valuable for protecting against race conditions
37 // within threaded applications. The CMutex class can be used to
38 // only allow a single thread to run within a specified code
39 // segment at a time.
41 // Public Methods:
42 // Lock() : Locks the mutex. If the mutex is already locked, the
43 // operating system will block the calling thread until another
44 // thread has unlocked the mutex.
45 // Unlock() : Unlocks the mutex.
47 class CMutex
49 public:
50 CMutex();
51 ~CMutex();
53 void Lock();
54 void Unlock();
55 private:
56 pthread_mutex_t mMutex;
57 bool mInitialized;
60 inline void CMutex::Lock(void)
62 if (mInitialized)
63 pthread_mutex_lock(&mMutex);
66 inline void CMutex::Unlock(void)
68 if (mInitialized)
69 pthread_mutex_unlock(&mMutex);
73 #ifdef EXTERNAL_DISTRO
75 #endif
76 #endif // #if defined(_MT)
78 #endif // BASE_LINUX_MUTEX_H