39 void Insert(PRITYPE pri,
const TYPE& e);
59template<
class PRITYPE,
class TYPE>
68template<
class PRITYPE,
class TYPE>
71 this->criticalSection.Enter();
72 this->queueArray = rhs.queueArray;
73 this->criticalSection.Leave();
79template<
class PRITYPE,
class TYPE>
void
82 this->criticalSection.Enter();
83 this->queueArray = rhs.queueArray;
84 this->criticalSection.Leave();
90template<
class PRITYPE,
class TYPE>
void
93 this->criticalSection.Enter();
94 this->queueArray.
Clear();
95 this->criticalSection.Leave();
101template<
class PRITYPE,
class TYPE>
SizeT
104 return this->queueArray.Size();
110template<
class PRITYPE,
class TYPE>
bool
113 return this->queueArray.IsEmpty();
119template<
class PRITYPE,
class TYPE>
void
123 this->criticalSection.Enter();
124 this->queueArray.InsertSorted(kvp);
125 this->criticalSection.Leave();
126 this->enqueueEvent.Signal();
132template<
class PRITYPE,
class TYPE>
void
135 this->criticalSection.Enter();
137 for (
auto iter = this->queueArray.Begin(); iter != this->queueArray.End();)
139 if ((*iter).Value() == e)
141 iter = this->queueArray.Erase(iter);
148 this->criticalSection.Leave();
154template<
class PRITYPE,
class TYPE> TYPE
157 this->criticalSection.Enter();
158 TYPE value = this->queueArray.Front().Value();
159 this->queueArray.EraseIndex(0);
160 this->criticalSection.Leave();
167template<
class PRITYPE,
class TYPE> TYPE
170 this->criticalSection.Enter();
171 TYPE value = this->queueArray.Front().Value();
172 this->criticalSection.Leave();
179template<
class PRITYPE,
class TYPE>
void
182 if (this->queueArray.Size() == 0)
184 this->enqueueEvent.Wait();
194template<
class PRITYPE,
class TYPE>
void
197 this->enqueueEvent.Signal();
Critical section objects are used to protect a portion of code from parallel execution.
A thread-safe priority-sorted queue which protects itself with critical sections.
Definition safepriorityqueue.h:22
void Signal()
signal the internal event, so that Wait() will return
Definition safepriorityqueue.h:195
bool IsEmpty() const
return true if queue is empty
Definition safepriorityqueue.h:111
SafePriorityQueue()
constructor
Definition safepriorityqueue.h:60
SizeT Size() const
returns number of elements in the queue
Definition safepriorityqueue.h:102
CriticalSection criticalSection
Definition safepriorityqueue.h:52
void EraseMatchingElements(const TYPE &e)
erase all matching elements
Definition safepriorityqueue.h:133
TYPE Dequeue()
remove the element from the front of the queue
Definition safepriorityqueue.h:155
TYPE Peek() const
get copy of element at front of queue without removing it
Definition safepriorityqueue.h:168
Event enqueueEvent
Definition safepriorityqueue.h:53
void Clear()
remove all elements from the queue
Definition safepriorityqueue.h:91
void operator=(const SafePriorityQueue< PRITYPE, TYPE > &rhs)
assignment operator
Definition safepriorityqueue.h:80
void Insert(PRITYPE pri, const TYPE &e)
add element to the back of the queue
Definition safepriorityqueue.h:120
void Wait()
wait until queue contains at least one element
Definition safepriorityqueue.h:180
Key/Value pair objects are used by most assiociative container classes, like Dictionary or HashTable.
Definition keyvaluepair.h:19
Nebula's queue class (a FIFO container).
Definition queue.h:28
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