00001 // $Id: TGo4Queue.cxx 478 2009-10-29 12:26:09Z linev $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "TGo4Queue.h" 00015 00016 #include "Riostream.h" 00017 00018 #include "TList.h" 00019 #include "TMutex.h" 00020 #include "TCondition.h" 00021 00022 #include "TGo4Log.h" 00023 #include "TGo4LockGuard.h" 00024 #include "TGo4RuntimeException.h" 00025 00026 TGo4Queue::TGo4Queue() : TNamed("Default Queue", "This is a Go4 Queue"), 00027 fiEntries(0), fiMaxEntries(100), fbWakeUpCall(kFALSE) 00028 { 00029 fxMutex=new TMutex; 00030 fxCondition=new TCondition; 00031 fxList= new TList; 00032 00033 } 00034 00035 TGo4Queue::TGo4Queue(const char* name) : TNamed(name, "This is a Go4 Queue"), 00036 fiEntries(0), fiMaxEntries(100), fbWakeUpCall(kFALSE) 00037 { 00038 fxMutex=new TMutex; 00039 fxCondition=new TCondition; 00040 fxList= new TList; 00041 } 00042 00043 TGo4Queue::~TGo4Queue() 00044 { 00045 delete fxList; 00046 delete fxCondition; 00047 delete fxMutex; 00048 } 00049 00050 void TGo4Queue::Clear(Option_t* opt) 00051 { 00052 TGo4LockGuard qguard(fxMutex); 00053 fxList->Clear(); 00054 } 00055 00056 TObject* TGo4Queue::Wait() 00057 { 00058 if(IsEmpty()) 00059 { 00060 //cout <<"WWWWWWWWWWWWWWWWWW --- TGo4Queue "<< GetName() <<" is in Condition Wait..." << endl; 00061 fxCondition->Wait(); 00062 if(fbWakeUpCall) 00063 { 00064 fbWakeUpCall=kFALSE; 00065 return 0; // signal by Wake(), give null back! 00066 } 00067 } 00068 return Next(); 00069 } 00070 00071 TObject* TGo4Queue::Next() 00072 { 00073 TGo4LockGuard qguard(fxMutex); 00074 return (fxList->Remove(fxList->LastLink()) ); 00075 } 00076 00077 void TGo4Queue::Add(TObject* ob) 00078 { 00079 { 00080 TGo4LockGuard qguard(fxMutex); 00081 if(fxList->GetSize() <= fiMaxEntries) 00082 { 00083 fxList->AddFirst(ob); 00084 //cout <<"QA Queue " <<GetName() <<" added obj, size="<<fxList->GetSize()<<endl; 00085 } 00086 else 00087 { 00088 //cout <<" Queue Add Error: queue "<< GetName() <<" is full !!!"<<endl; 00089 throw TGo4RuntimeException(); 00090 } 00091 } //TGo4LockGuard qguard(fxMutex); 00092 fxCondition->Signal(); 00093 00094 } 00095 00096 Bool_t TGo4Queue::IsEmpty() 00097 { 00098 TGo4LockGuard qguard(fxMutex); 00099 return (fxList->IsEmpty()); 00100 } 00101 00102 void TGo4Queue::Wake() 00103 { 00104 //cout <<"TGo4Queue::Wake() in "<<GetName() << endl; 00105 fbWakeUpCall=kTRUE; 00106 fxCondition->Signal(); 00107 }