Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4LockGuard.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4LockGuard.h"
00017 
00018 #include "Riostream.h"
00019 #include "TMutex.h"
00020 
00021 TMutex* TGo4LockGuard::fgxMainMutex=0;
00022 
00023 Int_t TGo4LockGuard::fgiLockCount=0;
00024 
00025 
00026 TGo4LockGuard::TGo4LockGuard (TMutex* mutex)
00027 {
00028    // first call: create main mutex
00029    if(fgxMainMutex==0)
00030       fgxMainMutex= new TMutex(kTRUE); // we use recursive mode for cascading lockguards
00031    if(mutex==0)
00032       {
00033          // use global mutex
00034          fxMutex=fgxMainMutex;
00035          fbIsMainMutex=kTRUE;
00036       }
00037    else
00038       {
00039          // use external mutex
00040          fxMutex=mutex;
00041          fbIsMainMutex=kFALSE;
00042       }
00043 
00044    if (TThread::Exists()>0)
00045       {
00046          // UInt_t id = TThread::SelfId();
00047          fxMutex->Lock();
00048          fbIsLocked=kTRUE;
00049          if(!fbIsMainMutex)
00050             {
00051 //             if(TGo4Log::GetIgnoreLevel()>5)
00052 //                {
00053 //                  cout <<"G-----{ Local Mutex "<< fxMutex << " acquired by thread id: "<<id << endl;
00054 //                }
00055             }
00056          else
00057             {
00058                fgiLockCount++;
00059                //if(TGo4Log::GetIgnoreLevel()>5)
00060 //                   {
00061 //                     cout <<"G-----{ Global Mutex "<< fxMutex << "acquired by thread id: "<<id;
00062 //                     cout<< ", count:"<< fgiLockCount << endl;
00063 //                   }
00064             }
00065       }
00066    else
00067       {
00068          // no thread, no lock
00069          fbIsLocked=kFALSE;
00070       }
00071 }
00072 
00073 TGo4LockGuard::~TGo4LockGuard()
00074 {
00075    if (fbIsLocked)
00076       {
00077         //UInt_t id = TThread::SelfId();
00078         if(!fbIsMainMutex)
00079            {
00080 //              if(TGo4Log::GetIgnoreLevel()>5)
00081 //                   {
00082 //                     cout <<"}-----G Local Mutex "<< fxMutex << "released by thread id: "<<id << endl;
00083 //                   }
00084            }
00085         else
00086             {
00087                fgiLockCount--;
00088 //               if(TGo4Log::GetIgnoreLevel()>5)
00089 //                   {
00090 //                     cout <<"}-----G Global Mutex "<< fxMutex << "released by thread id: "<<id << endl;
00091 //                     cout<< ", count:"<< fgiLockCount << endl;
00092 //                   }
00093             }
00094          fxMutex->UnLock();
00095       }
00096    else
00097       {
00098          // no woman, no cry
00099       }
00100 }
00101 
00102 void TGo4LockGuard::LockMainMutex()
00103 {
00104   fgxMainMutex->Lock();
00105 }
00106 
00107 void TGo4LockGuard::UnLockMainMutex()
00108 {
00109   fgxMainMutex->UnLock();
00110 }
00111 
00112 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:26 2008 for Go4-v3.04-1 by  doxygen 1.4.2