FACT++
1.0
Main Page
Related Pages
Namespaces
Classes
Files
Examples
template<class T, class List = std::list<T>>
void
Queue
< T, List >::Thread
(
)
inline
private
Definition at line
55
of file
Queue.h
.
Referenced by
Queue< pair< Time, GUI_STAT > >::start()
.
56
{
57
std::unique_lock<std::mutex> lock(
fMutex
);
58
59
// No filling allowed by default (the queue is
60
// always processed until it is empty)
61
size_t
allowed = 0;
62
63
while
(1)
64
{
65
while
(
fSize
==allowed &&
fState
==
kRun
)
66
fCond
.wait(lock);
67
68
// Check if the State flag has been changed
69
if
(
fState
==
kAbort
)
70
break
;
71
72
if
(
fState
==
kStop
&&
fList
.empty())
73
break
;
74
75
// If thread got just woken up, move back the state to kRun
76
if
(
fState
==
kTrigger
)
77
fState
=
kRun
;
78
79
// Could have been a fState==kTrigger case
80
if
(
fList
.empty())
81
continue
;
82
83
// During the unlocked state, fSize might change.
84
// The current size of the queue needs to be saved.
85
allowed =
fSize
;
86
87
// get the first entry from the (sorted) list
88
const
auto
it =
fList
.begin();
89
90
// Theoretically, we can loose a signal here, but this is
91
// not a problem, because then we detect a non-empty queue
92
lock.unlock();
93
94
// If the first event in the queue could not be processed,
95
// no further processing makes sense until a new event has
96
// been posted (or the number of events in the queue has
97
// changed) [allowed>0], in the case processing was
98
// successfull [allowed==0], the next event will be processed
99
// immediately.
100
101
if
(
fCallback
&&
fCallback
(*it))
102
allowed = 0;
103
104
lock.lock();
105
106
// Whenever an event was successfully processed, allowed
107
// is equal to zero and thus the event will be popped
108
if
(allowed>0)
109
continue
;
110
111
fList
.erase(it);
112
fSize
--;
113
}
114
115
fList
.clear();
116
fSize
= 0;
117
118
fState
=
kIdle
;
119
}
Queue::fList
List fList
Definition:
Queue.h:32
Queue::kTrigger
Definition:
Queue.h:43
Queue::fState
state_t fState
Definition:
Queue.h:48
Queue::kStop
Definition:
Queue.h:41
Queue::kIdle
Definition:
Queue.h:39
Queue::fCallback
callback fCallback
Definition:
Queue.h:51
Queue::kRun
Definition:
Queue.h:40
Queue::fCond
std::condition_variable fCond
Definition:
Queue.h:35
Queue::fMutex
std::mutex fMutex
Definition:
Queue.h:34
Queue::kAbort
Definition:
Queue.h:42
Queue::fSize
size_t fSize
Definition:
Queue.h:30
Here is the caller graph for this function:
Queue
Generated on Sun Sep 18 2016 20:50:56 for FACT++ by
1.8.11