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 "TGo4Queue.h" 00017 00018 #include <iostream.h> 00019 00020 #include "TList.h" 00021 #include "TMutex.h" 00022 #include "TCondition.h" 00023 00024 #include "Go4Log/TGo4Log.h" 00025 #include "Go4LockGuard/TGo4LockGuard.h" 00026 #include "Go4Exceptions/TGo4RuntimeException.h" 00027 00028 TGo4Queue::TGo4Queue() : TNamed("Default Queue", "This is a Go4 Queue"), 00029 fiEntries(0), fiMaxEntries(100), fbWakeUpCall(kFALSE) 00030 { 00031 fxMutex=new TMutex; 00032 fxCondition=new TCondition; 00033 fxList= new TList; 00034 00035 } 00036 00037 TGo4Queue::TGo4Queue(const char* name) : TNamed(name, "This is a Go4 Queue"), 00038 fiEntries(0), fiMaxEntries(100), fbWakeUpCall(kFALSE) 00039 { 00040 fxMutex=new TMutex; 00041 fxCondition=new TCondition; 00042 fxList= new TList; 00043 } 00044 00045 TGo4Queue::~TGo4Queue() 00046 { 00047 delete fxList; 00048 delete fxCondition; 00049 delete fxMutex; 00050 } 00051 00052 void TGo4Queue::Clear(Option_t* opt) 00053 { 00054 TGo4LockGuard qguard(fxMutex); 00055 fxList->Clear(); 00056 } 00057 00058 TObject* TGo4Queue::Wait() 00059 { 00060 if(IsEmpty()) 00061 { 00062 //cout <<"WWWWWWWWWWWWWWWWWW --- TGo4Queue "<< GetName() <<" is in Condition Wait..." << endl; 00063 fxCondition->Wait(); 00064 if(fbWakeUpCall) 00065 { 00066 fbWakeUpCall=kFALSE; 00067 return 0; // signal by Wake(), give null back! 00068 } 00069 } 00070 return Next(); 00071 } 00072 00073 TObject* TGo4Queue::Next() 00074 { 00075 TGo4LockGuard qguard(fxMutex); 00076 return (fxList->Remove(fxList->LastLink()) ); 00077 } 00078 00079 void TGo4Queue::Add(TObject* ob) 00080 { 00081 { 00082 TGo4LockGuard qguard(fxMutex); 00083 if(fxList->GetSize() <= fiMaxEntries) 00084 { 00085 fxList->AddFirst(ob); 00086 //cout <<"QA Queue " <<GetName() <<" added obj, size="<<fxList->GetSize()<<endl; 00087 } 00088 else 00089 { 00090 //cout <<" Queue Add Error: queue "<< GetName() <<" is full !!!"<<endl; 00091 throw TGo4RuntimeException(); 00092 } 00093 } //TGo4LockGuard qguard(fxMutex); 00094 fxCondition->Signal(); 00095 00096 } 00097 00098 Bool_t TGo4Queue::IsEmpty() 00099 { 00100 TGo4LockGuard qguard(fxMutex); 00101 return (fxList->IsEmpty()); 00102 } 00103 00104 void TGo4Queue::Wake() 00105 { 00106 //cout <<"TGo4Queue::Wake() in "<<GetName() << endl; 00107 fbWakeUpCall=kTRUE; 00108 fxCondition->Signal(); 00109 } 00110 00111 //----------------------------END OF GO4 SOURCE FILE ---------------------