FACT++  1.0
template<class T, class List = std::list<T>>
void Queue< T, List >::Thread ( )
inlineprivate

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  }
List fList
Definition: Queue.h:32
state_t fState
Definition: Queue.h:48
callback fCallback
Definition: Queue.h:51
std::condition_variable fCond
Definition: Queue.h:35
std::mutex fMutex
Definition: Queue.h:34
size_t fSize
Definition: Queue.h:30

+ Here is the caller graph for this function: