missing project/build files
[client-tools.git] / src / external / 3rd / library / soePlatform / CSAssist / utils / Base / solaris / Mutex.h
blobeba47fd888be6220e93143f53d4d6b779618b3d1
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_SOLARIS_MUTEX_H
13 #define BASE_SOLARIS_MUTEX_H
15 #if !defined(_REENTRANT)
16 # pragma message( "Excluding Base::CMutex - requires multi-threaded compile. (_REENTRANT)" )
17 #else
20 #include "Platform.h"
22 namespace Base
25 ////////////////////////////////////////
26 // Class:
27 // CMutex
29 // Purpose:
30 // Encapsulates the functionality of a mutually-exclusive device.
31 // This class is valuable for protecting against race conditions
32 // within threaded applications. The CMutex class can be used to
33 // only allow a single thread to run within a specified code
34 // segment at a time.
36 // Public Methods:
37 // Lock() : Locks the mutex. If the mutex is already locked, the
38 // operating system will block the calling thread until another
39 // thread has unlocked the mutex.
40 // Unlock() : Unlocks the mutex.
42 class CMutex
44 public:
45 CMutex();
46 ~CMutex();
48 void Lock();
49 void Unlock();
50 private:
51 pthread_mutex_t mMutex;
52 bool mInitialized;
55 inline void CMutex::Lock(void)
57 if (mInitialized)
58 pthread_mutex_lock(&mMutex);
61 inline void CMutex::Unlock(void)
63 if (mInitialized)
64 pthread_mutex_unlock(&mMutex);
69 #endif // #if defined(_MT)
71 #endif // BASE_SOLARIS_MUTEX_H