Logo ROOT   6.08/07
Reference Guide
TRWLock.h
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // Author: Fons Rademakers 04/01/2000
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TRWLock
13 #define ROOT_TRWLock
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TRWLock //
19 // //
20 // This class implements a reader/writer lock. A rwlock allows //
21 // a resource to be accessed by multiple reader threads but only //
22 // one writer thread. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #ifndef ROOT_TObject
27 #include "TObject.h"
28 #endif
29 #ifndef ROOT_TMutex
30 #include "TMutex.h"
31 #endif
32 #ifndef ROOT_TCondition
33 #include "TCondition.h"
34 #endif
35 
36 
37 class TRWLock : public TObject {
38 
39 private:
40  Int_t fReaders; // number of readers
41  Int_t fWriters; // number of writers
42  TMutex fMutex; // rwlock mutex
43  TCondition fLockFree; // rwlock condition variable
44 
45  TRWLock(const TRWLock &); // not implemented
46  TRWLock& operator=(const TRWLock&); // not implemented
47 
48 public:
49  TRWLock();
50  virtual ~TRWLock() { }
51 
52  Int_t ReadLock();
53  Int_t ReadUnLock();
54  Int_t WriteLock();
56 
57  ClassDef(TRWLock,0) // Reader/writer lock
58 };
59 
60 #endif
Int_t WriteUnLock()
Unlock writer lock.
Definition: TRWLock.cxx:93
Int_t WriteLock()
Obtain a writer lock. Returns always 0.
Definition: TRWLock.cxx:75
Definition: TMutex.h:34
Int_t ReadLock()
Obtain a reader lock. Returns always 0.
Definition: TRWLock.cxx:38
virtual ~TRWLock()
Definition: TRWLock.h:50
Int_t fReaders
Definition: TRWLock.h:40
int Int_t
Definition: RtypesCore.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t fWriters
Definition: TRWLock.h:41
TMutex fMutex
Definition: TRWLock.h:42
TCondition fLockFree
Definition: TRWLock.h:43
TRWLock & operator=(const TRWLock &)
Mother of all ROOT objects.
Definition: TObject.h:37
TRWLock()
Create reader/write lock.
Definition: TRWLock.cxx:29
Int_t ReadUnLock()
Unlock reader lock.
Definition: TRWLock.cxx:56