Go to the documentation of this file.00001 #ifndef _sys_Mutex_h
00002 #define _sys_Mutex_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 namespace qpid {
00023 namespace sys {
00024
00029 template <class L>
00030 class ScopedLock
00031 {
00032 public:
00033 ScopedLock(L& l) : mutex(l) { l.lock(); }
00034 ~ScopedLock() { mutex.unlock(); }
00035 private:
00036 L& mutex;
00037 };
00038
00039 template <class L>
00040 class ScopedUnlock
00041 {
00042 public:
00043 ScopedUnlock(L& l) : mutex(l) { l.unlock(); }
00044 ~ScopedUnlock() { mutex.lock(); }
00045 private:
00046 L& mutex;
00047 };
00048
00049 template <class L>
00050 class ScopedRlock
00051 {
00052 public:
00053 ScopedRlock(L& l) : mutex(l) { l.rlock(); }
00054 ~ScopedRlock() { mutex.unlock(); }
00055 private:
00056 L& mutex;
00057 };
00058
00059 template <class L>
00060 class ScopedWlock
00061 {
00062 public:
00063 ScopedWlock(L& l) : mutex(l) { l.wlock(); }
00064 ~ScopedWlock() { mutex.unlock(); }
00065 private:
00066 L& mutex;
00067 };
00068
00069 template <class L>
00070 class ConditionalScopedLock
00071 {
00072 public:
00073 ConditionalScopedLock(L& l) : mutex(l) { acquired = l.trylock(); }
00074 ~ConditionalScopedLock() { if (acquired) mutex.unlock(); }
00075 bool lockAcquired() { return acquired; }
00076 private:
00077 L& mutex;
00078 bool acquired;
00079 };
00080
00081 }}
00082
00083 #ifdef USE_APR_PLATFORM
00084 #include "apr/Mutex.h"
00085 #elif defined (_WIN32)
00086 #include "windows/Mutex.h"
00087 #else
00088 #include "posix/Mutex.h"
00089 #endif
00090
00091 #endif