Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4LockGuard/TGo4LockGuard.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE 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 <iostream.h>
00019 
00020 #include "TMutex.h"
00021 
00022 Int_t TGo4LockGuard::fgiLockCount=0;
00023 TMutex* TGo4LockGuard::fgxMainMutex=0;
00024 
00025 TGo4LockGuard::TGo4LockGuard (TMutex* mutex)
00026 {
00027    // first call: create main mutex
00028    if(fgxMainMutex==0)
00029       {
00030             fgxMainMutex= new TMutex(kTRUE); // we use recursive mode for cascading lockguards
00031       }
00032    if(mutex==0)
00033       {
00034          // use global mutex
00035          fxMutex=fgxMainMutex;
00036          fbIsMainMutex=kTRUE;
00037       }
00038    else
00039       {
00040          // use external mutex
00041          fxMutex=mutex;
00042          fbIsMainMutex=kFALSE;
00043       }
00044 
00045    if (TThread::Exists()>0)
00046       {
00047          //UInt_t id = TThread::SelfId();
00048          if(fxMutex) fxMutex->Lock();
00049          fbIsLocked=kTRUE;
00050          if(!fbIsMainMutex)
00051             {
00052 //             if(TGo4Log::GetIgnoreLevel()>5)
00053 //                {
00054 //                  cout <<"G-----{ Local Mutex "<< fxMutex << " acquired by thread id: "<<id << endl;
00055 //                }
00056             }
00057          else
00058             {
00059                fgiLockCount++;
00060                //if(TGo4Log::GetIgnoreLevel()>5)
00061 //                   {
00062 //                     cout <<"G-----{ Global Mutex "<< fxMutex << " and gCINTMutex: " << gCINTMutex <<" acquired by thread id: "<<id<< endl;
00063 //                     cout<< ", count:"<< fgiLockCount << endl;
00064 //                   }
00065                
00066             }
00067       }
00068    else
00069       {
00070          // no thread, no lock
00071          fbIsLocked=kFALSE;
00072       }
00073 }
00074 
00075 TGo4LockGuard::~TGo4LockGuard()
00076 {
00077    if (fbIsLocked)
00078       {
00079         //UInt_t id = TThread::SelfId();
00080         if(!fbIsMainMutex)
00081            {
00082 //              if(TGo4Log::GetIgnoreLevel()>5)
00083 //                   {
00084 //                     cout <<"}-----G Local Mutex "<< fxMutex << "released by thread id: "<<id << endl;
00085 //                   }
00086            }
00087         else
00088             {
00089                fgiLockCount--;
00090 //               if(TGo4Log::GetIgnoreLevel()>5)
00091 //                   {
00093 //                     cout<< ", count:"<< fgiLockCount << endl;
00094 //                   }
00095             }
00096          if(fxMutex) fxMutex->UnLock();
00097       }
00098    else
00099       {
00100          // no woman, no cry
00101       }
00102 }
00103 
00104 ClassImp(TGo4LockGuard)
00105 
00106 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:04 2005 for Go4-v2.10-5 by doxygen1.2.15