// $Id$ //----------------------------------------------------------------------- // The GSI Online Offline Object Oriented (Go4) Project // Experiment Data Processing at EE department, GSI //----------------------------------------------------------------------- // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH // Planckstr. 1, 64291 Darmstadt, Germany // Contact: http://go4.gsi.de //----------------------------------------------------------------------- // This software can be used under the license agreements as stated // in Go4License.txt file which is part of the distribution. //----------------------------------------------------------------------- #include "TGo4Queue.h" #include "TList.h" #include "TMutex.h" #include "TCondition.h" #include "TGo4LockGuard.h" #include "TGo4RuntimeException.h" TGo4Queue::TGo4Queue(const char *name) : TNamed(name ? name : "Default Queue", "This is a Go4 Queue"), fiEntries(0), fiMaxEntries(100), fbWakeUpCall(kFALSE) { fxMutex = new TMutex; fxCondition = new TCondition; fxList = new TList; } TGo4Queue::~TGo4Queue() { //printf ("JAM*************** DTOR of TGo4Queue %s BEGIN\n", GetName()); delete fxList; fxList = nullptr; delete fxCondition; fxCondition = nullptr; delete fxMutex; fxMutex = nullptr; // printf ("JAM*************** DTOR of TGo4Queue %s END\n", GetName()); } void TGo4Queue::Clear(Option_t *) { TGo4LockGuard qguard(fxMutex); fxList->Clear(); } TObject *TGo4Queue::Wait() { if (IsEmpty()) { fxCondition->Wait(); if (fbWakeUpCall) { fbWakeUpCall = kFALSE; return nullptr; // signal by Wake(), give null back! } } return Next(); } TObject *TGo4Queue::Next() { TGo4LockGuard qguard(fxMutex); return fxList->Remove(fxList->LastLink()); } void TGo4Queue::Add(TObject *ob) { { TGo4LockGuard qguard(fxMutex); if (fxList->GetSize() <= fiMaxEntries) { fxList->AddFirst(ob); } else { throw TGo4RuntimeException(); } } fxCondition->Signal(); } Bool_t TGo4Queue::IsEmpty() const { TGo4LockGuard qguard(fxMutex); return fxList->IsEmpty(); } void TGo4Queue::Wake() { fbWakeUpCall = kTRUE; fxCondition->Signal(); }