78 signalOnEnqueueEnabled(true)
89 this->criticalSection.Enter();
90 this->queue = rhs.
queue;
92 this->criticalSection.Leave();
98template<
class TYPE>
void
101 this->criticalSection.Enter();
102 this->queue = rhs.
queue;
104 this->criticalSection.Leave();
110template<
class TYPE>
void
113 this->criticalSection.Enter();
114 this->signalOnEnqueueEnabled = b;
115 this->criticalSection.Leave();
121template<
class TYPE>
void
124 this->criticalSection.Enter();
126 this->criticalSection.Leave();
132template<
class TYPE>
SizeT
135 return this->queue.Size();
141template<
class TYPE>
bool
144 this->criticalSection.Enter();
145 bool isEmpty = this->queue.IsEmpty();
146 this->criticalSection.Leave();
153template<
class TYPE>
void
156 this->criticalSection.Enter();
157 this->queue.Enqueue(e);
158 this->criticalSection.Leave();
159 if (this->signalOnEnqueueEnabled)
161 this->enqueueEvent.Signal();
168template<
class TYPE>
void
171 this->criticalSection.Enter();
172 this->queue.Enqueue(std::move(e));
173 this->criticalSection.Leave();
174 if (this->signalOnEnqueueEnabled)
176 this->enqueueEvent.Signal();
183template<
class TYPE>
void
186 this->criticalSection.Enter();
189 this->queue.Enqueue(i);
191 this->criticalSection.Leave();
192 if (this->signalOnEnqueueEnabled)
194 this->enqueueEvent.Signal();
201template<
class TYPE> TYPE
204 this->criticalSection.Enter();
205 TYPE e = this->queue.Dequeue();
206 this->criticalSection.Leave();
213template<
class TYPE>
void
216 this->criticalSection.Enter();
217#if NEBULA_ENABLE_PERFORMANCE_WARNINGS
218 n_warn_fmt(outArray.
Capacity() >= this->queue.Size(),
"SafeQueue::DequeueAll(): (PERFORMANCE) Output array is too small (%d), requires (%d), array will have to grow.\n", outArray.
Capacity(), this->queue.Size());
221 for (
IndexT i = 0; i < this->queue.Size(); i++)
223 outArray.
Append(std::move(this->queue[i]));
226 this->criticalSection.Leave();
232template<
class TYPE> TYPE
235 this->criticalSection.Enter();
236 TYPE e = this->queue.Peek();
237 this->criticalSection.Leave();
244template<
class TYPE>
void
247 if (this->signalOnEnqueueEnabled && this->IsEmpty())
249 this->enqueueEvent.Wait();
256template<
class TYPE>
void
259 if (this->signalOnEnqueueEnabled && this->IsEmpty())
261 this->enqueueEvent.WaitTimeout(ms);
271template<
class TYPE>
void
274 this->enqueueEvent.Signal();
280template<
class TYPE>
void
283 this->criticalSection.Enter();
285 for (i = this->queue.Size() - 1; i >= 0; i--)
287 if (e == this->queue[i])
289 this->queue.EraseIndex(i);
292 this->criticalSection.Leave();
Critical section objects are used to protect a portion of code from parallel execution.
Thread-safe version of Util::Queue.
Definition safequeue.h:27
void DequeueAll(Util::Array< TYPE > &outArray)
dequeue all events (only requires one lock)
Definition safequeue.h:214
void Signal()
signal the internal event, so that Wait() will return
Definition safequeue.h:272
void EnqueueArray(const Util::Array< TYPE > &a)
enqueue an array of elements
Definition safequeue.h:184
TYPE Peek() const
access to element at front of queue without removing it
Definition safequeue.h:233
void EraseMatchingElements(const TYPE &e)
erase all matching elements
Definition safequeue.h:281
SafeQueue(const SafeQueue< TYPE > &rhs)
copy constructor
Definition safequeue.h:87
bool IsEmpty() const
return true if queue is empty
Definition safequeue.h:142
void WaitTimeout(int ms)
wait until queue contains at least one element, or time-out happens
Definition safequeue.h:257
void SetSignalOnEnqueueEnabled(bool b)
enable/disable signalling on Enqueue() (default is enabled)
Definition safequeue.h:111
Event enqueueEvent
Definition safequeue.h:68
void Enqueue(const TYPE &e)
add element to the back of the queue
Definition safequeue.h:154
void Wait()
wait until queue contains at least one element
Definition safequeue.h:245
Util::Queue< TYPE > queue
Definition safequeue.h:70
bool signalOnEnqueueEnabled
Definition safequeue.h:69
TYPE Dequeue()
remove the element from the front of the queue
Definition safequeue.h:202
bool IsSignalOnEnqueueEnabled() const
return signalling-on-Enqueue() flag
SizeT Size() const
returns number of elements in the queue
Definition safequeue.h:133
void operator=(const SafeQueue< TYPE > &rhs)
assignment operator
Definition safequeue.h:99
SafeQueue()
constructor
Definition safequeue.h:77
void Clear()
remove all elements from the queue
Definition safequeue.h:122
void Enqueue(TYPE &&e)
Definition safequeue.h:169
CriticalSection criticalSection
Definition safequeue.h:67
Nebula's dynamic array class.
Definition array.h:60
const SizeT Capacity() const
get overall allocated size of array in number of elements
Definition array.h:898
void Clear()
clear array (calls destructors)
Definition array.h:1205
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1332
Nebula's queue class (a FIFO container).
Definition queue.h:28
#define n_warn_fmt(exp, msg,...)
Definition debug.h:56
The Jobs2 system provides a set of threads and a pool of jobs from which threads can pickup work.
Definition jobs2.h:16
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48