GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4LockGuard.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4LockGuard.h"
15
16#include "TMutex.h"
17
18TMutex *TGo4LockGuard::fgxMainMutex = nullptr;
19
21
22
23TGo4LockGuard::TGo4LockGuard (TMutex *mutex, Bool_t)
24{
25 // first call: create main mutex
26 // std::cout <<"G-----TGo4LockGuard ctor" << std::endl;
27 //
28 if(!fgxMainMutex)
29 fgxMainMutex = new TMutex(kTRUE); // we use recursive mode for cascading lockguards
30 if(!mutex) {
31 // use global mutex
33 fbIsMainMutex = kTRUE;
34 } else {
35 // use external mutex
36 fxMutex = mutex;
37 fbIsMainMutex = kFALSE;
38 }
39
40 fxMutex->Lock();
41 fbIsLocked = kTRUE;
43}
44
46{
47 if (fbIsLocked) {
49 fxMutex->UnLock();
50 }
51}
52
57
59{
60 fgxMainMutex->Lock();
61}
62
64{
65 fgxMainMutex->UnLock();
66}
TGo4LockGuard(TMutex *mutex=nullptr, Bool_t=kFALSE)
Bool_t fbIsLocked
We need this flag if first TThread starts in between ctor and dtor.
static void LockMainMutex()
static Int_t MainMutexLockCount()
static void UnLockMainMutex()
virtual ~TGo4LockGuard()
static Int_t fgiLockCount
Counts the numbers of locks of the recursive main mutex.
Bool_t fbIsMainMutex
True if the mutex of this lockguard instance is the global go4 main mutex.
static TMutex * fgxMainMutex
Main Mutex of the go4 system.
TMutex * fxMutex
Reference to Mutex associated with this lockguard (external or internal)