00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _rwlock_h
00018 #define _rwlock_h
00019
00020 #include <spl/threading/Event.h>
00021
00028 class RWLock;
00029 typedef RefCountPtr<RWLock> RWLockPtr;
00030 typedef WeakReference<RWLock, RWLockPtr> RWLockRef;
00031
00032 REGISTER_TYPEOF( 466, RWLockPtr );
00033 REGISTER_TYPEOF( 468, RWLockRef );
00034
00038 class RWLock
00039 {
00040 private:
00041
00042 inline RWLock(const RWLock& rw) {}
00043 inline void operator =(const RWLock& rw) {}
00044
00045 protected:
00046
00047 #if defined(_WINDOWS) || defined(__TANDEM)
00048
00049 Mutex m_stateMtx;
00050 volatile int m_readLockCount;
00051 volatile int m_writeLockCount;
00052
00053 Event m_waitingWriters;
00054 volatile int m_waitingWritersCount;
00055
00056 Event m_waitingReaders;
00057 volatile int m_waitingReadersCount;
00058
00059 #else
00060 pthread_rwlock_t m_rwlock;
00061 #endif
00062
00063 public:
00064 RWLock();
00065 virtual ~RWLock();
00066
00067 void LockRead();
00068 void LockWrite();
00069 void UnlockRead();
00070 void UnlockWrite();
00071 };
00072
00073 inline void ValidateType(const RWLock& rw)
00074 {
00075 }
00076
00077 REGISTER_TYPEOF( 470, RWLock );
00078
00081 #endif