00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef header_mutex
00030 #define header_mutex
00031
00032 #ifndef WIN32
00033 #ifndef __USE_UNIX98
00034 #define __USE_UNIX98
00035 #endif
00036 #include <pthread.h>
00037 #endif
00038
00039 class CL_Mutex
00040 {
00042 public:
00043 CL_Mutex();
00044
00045 ~CL_Mutex();
00046
00048 public:
00049
00051 public:
00052 void lock();
00053
00054 bool try_lock();
00055
00056 void unlock();
00057
00059 private:
00060 #ifdef WIN32
00061 CRITICAL_SECTION critical_section;
00062 #else
00063 pthread_mutex_t handle;
00064 #endif
00065 };
00066
00067 class CL_MutexSection
00068 {
00070 public:
00071 CL_MutexSection(CL_Mutex *mutex, bool lock = true);
00072
00073 ~CL_MutexSection();
00074
00076 public:
00077 int get_lock_count() const;
00078
00080 public:
00081 void lock();
00082
00083 bool try_lock();
00084
00085 void unlock();
00086
00088 private:
00089 CL_Mutex *mutex;
00090
00091 int lock_count;
00092 };
00093
00094 #endif