GSI Object Oriented Online Offline (Go4)
GO4-6.4.0
Loading...
Searching...
No Matches
Go4Queue
TGo4Queue.cxx
Go to the documentation of this file.
1
// $Id$
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 fuer 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 "TGo4LockGuard.h"
21
#include "
TGo4RuntimeException.h
"
22
23
TGo4Queue::TGo4Queue
(
const
char
*name) :
24
TNamed(name ? name :
"Default Queue"
,
"This is a Go4 Queue"
),
25
fiEntries
(0),
26
fiMaxEntries
(100),
27
fbWakeUpCall
(kFALSE)
28
{
29
fxMutex
=
new
TMutex;
30
fxCondition
=
new
TCondition;
31
fxList
=
new
TList;
32
}
33
34
TGo4Queue::~TGo4Queue
()
35
{
36
//printf ("JAM*************** DTOR of TGo4Queue %s BEGIN\n", GetName());
37
delete
fxList
;
fxList
=
nullptr
;
38
delete
fxCondition
;
fxCondition
=
nullptr
;
39
delete
fxMutex
;
fxMutex
=
nullptr
;
40
// printf ("JAM*************** DTOR of TGo4Queue %s END\n", GetName());
41
}
42
43
void
TGo4Queue::Clear
(Option_t *)
44
{
45
TGo4LockGuard
qguard(
fxMutex
);
46
fxList
->Clear();
47
}
48
49
TObject *
TGo4Queue::Wait
()
50
{
51
if
(
IsEmpty
()) {
52
fxCondition
->Wait();
53
if
(
fbWakeUpCall
) {
54
fbWakeUpCall
= kFALSE;
55
return
nullptr
;
// signal by Wake(), give null back!
56
}
57
}
58
return
Next
();
59
}
60
61
TObject *
TGo4Queue::Next
()
62
{
63
TGo4LockGuard
qguard(
fxMutex
);
64
return
fxList
->Remove(
fxList
->LastLink());
65
}
66
67
void
TGo4Queue::Add
(TObject *ob)
68
{
69
{
70
TGo4LockGuard
qguard(
fxMutex
);
71
if
(
fxList
->GetSize() <=
fiMaxEntries
) {
72
fxList
->AddFirst(ob);
73
}
else
{
74
throw
TGo4RuntimeException
();
75
}
76
}
77
fxCondition
->Signal();
78
}
79
80
Bool_t
TGo4Queue::IsEmpty
()
const
81
{
82
TGo4LockGuard
qguard(
fxMutex
);
83
return
fxList
->IsEmpty();
84
}
85
86
void
TGo4Queue::Wake
()
87
{
88
fbWakeUpCall
= kTRUE;
89
fxCondition
->Signal();
90
}
TGo4LockGuard
#define TGo4LockGuard
Definition
QRootCanvas.cpp:59
TGo4Queue.h
TGo4RuntimeException.h
TGo4Queue::Next
TObject * Next()
Definition
TGo4Queue.cxx:61
TGo4Queue::~TGo4Queue
virtual ~TGo4Queue()
Definition
TGo4Queue.cxx:34
TGo4Queue::fxList
TList * fxList
Definition
TGo4Queue.h:55
TGo4Queue::fiEntries
Int_t fiEntries
Definition
TGo4Queue.h:56
TGo4Queue::fiMaxEntries
Int_t fiMaxEntries
Definition
TGo4Queue.h:57
TGo4Queue::fxMutex
TMutex * fxMutex
Definition
TGo4Queue.h:53
TGo4Queue::Add
void Add(TObject *ob)
Definition
TGo4Queue.cxx:67
TGo4Queue::Clear
void Clear(Option_t *opt="") override
Definition
TGo4Queue.cxx:43
TGo4Queue::Wake
virtual void Wake()
Definition
TGo4Queue.cxx:86
TGo4Queue::TGo4Queue
TGo4Queue(const char *name=nullptr)
Definition
TGo4Queue.cxx:23
TGo4Queue::IsEmpty
Bool_t IsEmpty() const
Definition
TGo4Queue.cxx:80
TGo4Queue::Wait
TObject * Wait()
Definition
TGo4Queue.cxx:49
TGo4Queue::fxCondition
TCondition * fxCondition
Definition
TGo4Queue.h:54
TGo4Queue::fbWakeUpCall
Bool_t fbWakeUpCall
Definition
TGo4Queue.h:58
TGo4RuntimeException
Definition
TGo4RuntimeException.h:19
Generated by
1.13.2