00001 // @(#)root/thread:$Id: TRWLock.h 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Fons Rademakers 04/01/2000 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TRWLock 00013 #define ROOT_TRWLock 00014 00015 00016 ////////////////////////////////////////////////////////////////////////// 00017 // // 00018 // TRWLock // 00019 // // 00020 // This class implements a reader/writer lock. A rwlock allows // 00021 // a resource to be accessed by multiple reader threads but only // 00022 // one writer thread. // 00023 // // 00024 ////////////////////////////////////////////////////////////////////////// 00025 00026 #ifndef ROOT_TObject 00027 #include "TObject.h" 00028 #endif 00029 #ifndef ROOT_TMutex 00030 #include "TMutex.h" 00031 #endif 00032 #ifndef ROOT_TCondition 00033 #include "TCondition.h" 00034 #endif 00035 00036 00037 class TRWLock : public TObject { 00038 00039 private: 00040 Int_t fReaders; // number of readers 00041 Int_t fWriters; // number of writers 00042 TMutex fMutex; // rwlock mutex 00043 TCondition fLockFree; // rwlock condition variable 00044 00045 TRWLock(const TRWLock &); // not implemented 00046 TRWLock& operator=(const TRWLock&); // not implemented 00047 00048 public: 00049 TRWLock(); 00050 virtual ~TRWLock() { } 00051 00052 Int_t ReadLock(); 00053 Int_t ReadUnLock(); 00054 Int_t WriteLock(); 00055 Int_t WriteUnLock(); 00056 00057 ClassDef(TRWLock,0) // Reader/writer lock 00058 }; 00059 00060 #endif