00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __MUTEX__
00023 #define __MUTEX__
00024
00025 #if USE_PTHREADS != 1
00026 #error USE_PTHREADS was not set to 1 in your settings.cfg file, but you are including files that require this. Please fix your settings.cfg
00027 #endif
00028
00029 #include <pthread.h>
00030 #include "Lock.hxx"
00031 #include <errno.h>
00032
00033
00034
00035 namespace CLAM
00036 {
00037
00038 struct xtime;
00048 class Mutex
00049 {
00050 public:
00051
00052 friend class Hidden::LockOps<Mutex>;
00053 friend class Hidden::ScopedLock<Mutex>;
00054
00055 typedef Hidden::ScopedLock<Mutex> ScopedLock;
00056
00057 Mutex();
00058
00059 ~Mutex();
00060
00061 private:
00062
00063 struct ConditionVar
00064 {
00065 pthread_mutex_t* pmutex;
00066 };
00067
00068 void DoLock();
00069
00070 void DoUnlock();
00071
00072 void DoLock( ConditionVar& state );
00073
00074 void DoUnlock( ConditionVar& state );
00075
00076 pthread_mutex_t mMutex;
00077
00078 };
00079
00080 class TryMutex
00081 {
00082 public:
00083 friend class Hidden::LockOps<TryMutex>;
00084
00085 typedef Hidden::ScopedLock<TryMutex> ScopedLock;
00086 typedef Hidden::ScopedTryLock<TryMutex> ScopedTryLock;
00087
00088 TryMutex();
00089 ~TryMutex();
00090
00091 private:
00092 struct ConditionVar
00093 {
00094 pthread_mutex_t* pmutex;
00095 };
00096
00097 void DoLock();
00098
00099 bool DoTryLock();
00100
00101 void DoUnlock();
00102
00103 void DoLock( ConditionVar& state );
00104
00105 void DoUnlock( ConditionVar& state );
00106
00107 pthread_mutex_t mMutex;
00108
00109 };
00110
00111 class TimedMutex
00112 {
00113 public:
00114 friend class Hidden::LockOps<TimedMutex>;
00115
00116 typedef Hidden::ScopedLock<TimedMutex> ScopedLock;
00117 typedef Hidden::ScopedTryLock<TimedMutex> ScopedTryLock;
00118 typedef Hidden::ScopedTimedLock<TimedMutex> ScopedTimedLock;
00119
00120 TimedMutex();
00121 ~TimedMutex();
00122
00123 private:
00124 struct ConditionVar
00125 {
00126 pthread_mutex_t* pmutex;
00127 };
00128
00129 void DoLock();
00130
00131 bool DoTryLock();
00132
00133 bool DoTimedLock( const xtime& xt );
00134
00135 void DoUnlock();
00136
00137 void DoLock( ConditionVar& state );
00138
00139 void DoUnlock( ConditionVar& state );
00140
00141 pthread_mutex_t mMutex;
00142
00143 pthread_cond_t mCondition;
00144
00145 bool mLocked;
00146
00147 };
00148
00149 }
00150
00151 #endif // Mutex.hxx
00152