Logo ROOT   6.08/07
Reference Guide
TSemaphore.h
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // Author: Fons Rademakers 02/07/97 (Revised: G Ganis, Nov 2015)
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 // TSemaphore //
18 // //
19 // This class implements a counting semaphore. Use a semaphore //
20 // to synchronize threads. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include <mutex>
25 #include <condition_variable>
26 
27 #ifndef ROOT_TObject
28 #include "TObject.h"
29 #endif
30 
31 class TSemaphore : public TObject {
32 
33 private:
34  std::mutex fMutex; // semaphore mutex
35  std::condition_variable fCond; // semaphore condition variable
36  Int_t fValue; // semaphore value
37  UInt_t fWakeups; // wakeups
38 
39  TSemaphore(const TSemaphore &s) = delete; // not implemented
40  TSemaphore& operator=(const TSemaphore &s) = delete; // not implemented
41 
42 public:
43  TSemaphore(Int_t initial = 1);
44  virtual ~TSemaphore() { }
45 
46  Int_t Wait();
47  Int_t Wait(Int_t millisec);
48  Int_t TryWait();
49  Int_t Post();
50 
51  ClassDef(TSemaphore, 0) // Counting semaphore
52 };
53 
54 #endif
std::mutex fMutex
Definition: TSemaphore.h:34
Int_t TryWait()
If the semaphore value is > 0 then decrement it and return 0.
Definition: TSemaphore.cxx:87
virtual ~TSemaphore()
Definition: TSemaphore.h:44
int Int_t
Definition: RtypesCore.h:41
#define ClassDef(name, id)
Definition: Rtypes.h:254
TSemaphore & operator=(const TSemaphore &s)=delete
std::condition_variable fCond
Definition: TSemaphore.h:35
UInt_t fWakeups
Definition: TSemaphore.h:37
Int_t Wait()
If the semaphore value is > 0 then decrement it and carry on, else block, waiting on the condition un...
Definition: TSemaphore.cxx:35
TSemaphore(const TSemaphore &s)=delete
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t Post()
Increment the value of the semaphore.
Definition: TSemaphore.cxx:103
Int_t fValue
Definition: TSemaphore.h:36
Mother of all ROOT objects.
Definition: TObject.h:37