Logo ROOT  
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#include "TObject.h"
28
29class TSemaphore : public TObject {
30
31private:
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;
38 TSemaphore& operator=(const TSemaphore &s) = delete;
39
40public:
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
int Int_t
Definition: RtypesCore.h:45
#define ClassDef(name, id)
Definition: Rtypes.h:325
Mother of all ROOT objects.
Definition: TObject.h:37
UInt_t fWakeups
Definition: TSemaphore.h:35
TSemaphore & operator=(const TSemaphore &s)=delete
std::mutex fMutex
Definition: TSemaphore.h:32
Int_t TryWait()
If the semaphore value is > 0 then decrement it and return 0.
Definition: TSemaphore.cxx:87
std::condition_variable fCond
Definition: TSemaphore.h:33
Int_t Post()
Increment the value of the semaphore.
Definition: TSemaphore.cxx:103
virtual ~TSemaphore()
Definition: TSemaphore.h:42
Int_t fValue
Definition: TSemaphore.h:34
TSemaphore(const TSemaphore &s)=delete
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
static constexpr double s