• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/threading/RWLock.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
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         // forbid copy constructor
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