Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 #include "TObject.h"
28 
29 class TSemaphore : public TObject {
30 
31 private:
32  std::mutex fMutex; // semaphore mutex
33  std::condition_variable fCond; // semaphore condition variable
34  Int_t fValue; // semaphore value
35  UInt_t fWakeups; // wakeups
36 
37  TSemaphore(const TSemaphore &s) = delete; // not implemented
38  TSemaphore& operator=(const TSemaphore &s) = delete; // not implemented
39 
40 public:
41  TSemaphore(Int_t initial = 1);
42  virtual ~TSemaphore() { }
43 
44  Int_t Wait();
45  Int_t Wait(Int_t millisec);
46  Int_t TryWait();
47  Int_t Post();
48 
49  ClassDef(TSemaphore, 0) // Counting semaphore
50 };
51 
52 #endif