ROOT  6.06/09
Reference Guide
TSemaphore.h
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // Author: Fons Rademakers 02/07/97
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_TSemaphore
13 #define ROOT_TSemaphore
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TSemaphore //
19 // //
20 // This class implements a counting semaphore. Use a semaphore //
21 // to synchronize threads. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #ifndef ROOT_TObject
26 #include "TObject.h"
27 #endif
28 #ifndef ROOT_TMutex
29 #include "TMutex.h"
30 #endif
31 #ifndef ROOT_TCondition
32 #include "TCondition.h"
33 #endif
34 
35 
36 class TSemaphore : public TObject {
37 
38 private:
39  TMutex fMutex; // semaphare mutex
40  TCondition fCond; // semaphore condition variable
41  Int_t fValue; // counter
42 
43  TSemaphore(const TSemaphore &s); // not implemented
44  TSemaphore& operator=(const TSemaphore &s); // not implemented
45 
46 public:
47  TSemaphore(UInt_t initial = 1);
48  virtual ~TSemaphore() { }
49 
50  Int_t Wait(Int_t millisec = 0);
51  Int_t TryWait();
52  Int_t Post();
53 
54  ClassDef(TSemaphore,0) // Counting semaphore class
55 };
56 
57 #endif
Definition: TMutex.h:37
Int_t TryWait()
If semaphore value is > 0 then decrement it and return 0.
Definition: TSemaphore.cxx:81
Int_t Wait(Int_t millisec=0)
If semaphore value is > 0 then decrement it and carry on.
Definition: TSemaphore.cxx:38
virtual ~TSemaphore()
Definition: TSemaphore.h:48
int Int_t
Definition: RtypesCore.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:254
TMutex fMutex
Definition: TSemaphore.h:39
TCondition fCond
Definition: TSemaphore.h:40
TSemaphore(const TSemaphore &s)
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t Post()
If any threads are blocked in Wait(), wake one of them up and increment the value of the semaphore...
Definition: TSemaphore.cxx:105
Int_t fValue
Definition: TSemaphore.h:41
TSemaphore & operator=(const TSemaphore &s)
Mother of all ROOT objects.
Definition: TObject.h:58