GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4Queue.cxx
Go to the documentation of this file.
1 // $Id: TGo4Queue.cxx 2162 2018-10-10 14:16:24Z adamczew $
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 f�r 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 "TGo4Queue.h"
15 
16 #include "TList.h"
17 #include "TMutex.h"
18 #include "TCondition.h"
19 
20 #include "TGo4Log.h"
21 #include "TGo4LockGuard.h"
22 #include "TGo4RuntimeException.h"
23 
24 TGo4Queue::TGo4Queue(const char* name) :
25  TNamed(name ? name : "Default Queue", "This is a Go4 Queue"),
26  fiEntries(0),
27  fiMaxEntries(100),
28  fbWakeUpCall(kFALSE)
29 {
30  fxMutex = new TMutex;
31  fxCondition = new TCondition;
32  fxList = new TList;
33 }
34 
36 {
37 
38  //printf ("JAM*************** DTOR of TGo4Queue %s BEGIN\n", GetName());
39  delete fxList; fxList = 0;
40  delete fxCondition; fxCondition = 0;
41  delete fxMutex; fxMutex = 0;
42  // printf ("JAM*************** DTOR of TGo4Queue %s END\n", GetName());
43 }
44 
45 void TGo4Queue::Clear(Option_t* opt)
46 {
47  TGo4LockGuard qguard(fxMutex);
48  fxList->Clear();
49 }
50 
51 TObject* TGo4Queue::Wait()
52 {
53  if(IsEmpty()) {
54  //std::cout <<"WWWWWWWWWWWWWWWWWW --- TGo4Queue "<< GetName() <<" is in Condition Wait..." << std::endl;
55  fxCondition->Wait();
56  if(fbWakeUpCall) {
57  fbWakeUpCall = kFALSE;
58  return 0; // signal by Wake(), give null back!
59  }
60  }
61  return Next();
62 }
63 
64 TObject* TGo4Queue::Next()
65 {
66  TGo4LockGuard qguard(fxMutex);
67  return (fxList->Remove(fxList->LastLink()) );
68 }
69 
70 void TGo4Queue::Add(TObject* ob)
71 {
72  {
73  TGo4LockGuard qguard(fxMutex);
74  if(fxList->GetSize() <= fiMaxEntries)
75  {
76  fxList->AddFirst(ob);
77  //std::cout <<"QA Queue " <<GetName() <<" added obj, size="<<fxList->GetSize()<< std::endl;
78  }
79  else
80  {
81  //std::cout <<" Queue Add Error: queue "<< GetName() <<" is full !!!"<< std::endl;
82  throw TGo4RuntimeException();
83  }
84  } //TGo4LockGuard qguard(fxMutex);
85  fxCondition->Signal();
86 }
87 
89 {
90  TGo4LockGuard qguard(fxMutex);
91  return fxList->IsEmpty();
92 }
93 
95 {
96  //std::cout <<"TGo4Queue::Wake() in "<<GetName() << std::endl;
97  fbWakeUpCall = kTRUE;
98  fxCondition->Signal();
99 }
void Add(TObject *ob)
Definition: TGo4Queue.cxx:70
TGo4Queue(const char *name=0)
Definition: TGo4Queue.cxx:24
virtual void Wake()
Definition: TGo4Queue.cxx:94
Bool_t fbWakeUpCall
Definition: TGo4Queue.h:58
virtual ~TGo4Queue()
Definition: TGo4Queue.cxx:35
TMutex * fxMutex
Definition: TGo4Queue.h:53
Bool_t IsEmpty()
Definition: TGo4Queue.cxx:88
TCondition * fxCondition
Definition: TGo4Queue.h:54
Int_t fiMaxEntries
Definition: TGo4Queue.h:57
TObject * Wait()
Definition: TGo4Queue.cxx:51
TList * fxList
Definition: TGo4Queue.h:55
virtual void Clear(Option_t *opt="")
Definition: TGo4Queue.cxx:45
TObject * Next()
Definition: TGo4Queue.cxx:64