Nebula
Loading...
Searching...
No Matches
Threading::SafePriorityQueue< PRITYPE, TYPE > Class Template Reference

#include <safepriorityqueue.h>

Detailed Description

template<class PRITYPE, class TYPE>
class Threading::SafePriorityQueue< PRITYPE, TYPE >

A thread-safe priority-sorted queue which protects itself with critical sections.

Offers a method to wait for new elements to be added. Useful for inter-thread communications.

Inherits Util::Queue< Util::KeyValuePair< PRITYPE, TYPE > >.

Public Member Functions

 SafePriorityQueue ()
 constructor
 
 SafePriorityQueue (const SafePriorityQueue< PRITYPE, TYPE > &rhs)
 copy constructor
 
void operator= (const SafePriorityQueue< PRITYPE, TYPE > &rhs)
 assignment operator
 
SizeT Size () const
 returns number of elements in the queue
 
bool IsEmpty () const
 return true if queue is empty
 
void Clear ()
 remove all elements from the queue
 
void Insert (PRITYPE pri, const TYPE &e)
 add element to the back of the queue
 
void EraseMatchingElements (const TYPE &e)
 erase all matching elements
 
TYPE Dequeue ()
 remove the element from the front of the queue
 
TYPE Peek () const
 get copy of element at front of queue without removing it
 
void Wait ()
 wait until queue contains at least one element
 
void Signal ()
 signal the internal event, so that Wait() will return
 

Protected Attributes

CriticalSection criticalSection
 
Event enqueueEvent
 
- Protected Attributes inherited from Util::Queue< Util::KeyValuePair< PRITYPE, TYPE > >
TYPE * data
 
SizeT grow
 
SizeT start
 
SizeT size
 
SizeT capacity
 

Additional Inherited Members

- Protected Member Functions inherited from Util::Queue< Util::KeyValuePair< PRITYPE, TYPE > >
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type DestroyElement (IndexT idx)
 
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type DestroyElement (IndexT idx)
 
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==false >::type ClearAll ()
 
__forceinline std::enable_if< std::is_trivially_destructible< X >::value==true >::type ClearAll ()
 
IndexT MapIndex (IndexT index) const
 maps index to actual item position using wrapping
 
 Queue ()
 constructor
 
 Queue (const Queue< TYPE > &rhs)
 copy constructor
 
 Queue (Queue< TYPE > &&rhs)
 move constructor
 
 ~Queue ()
 destructor
 
void operator= (const Queue< TYPE > &rhs)
 assignment operator
 
void operator= (Queue< TYPE > &&rhs)
 move assignment operator
 
TYPE & operator[] (IndexT index) const
 access element by index, 0 is the frontmost element (next to be dequeued)
 
bool operator== (const Queue< TYPE > &rhs) const
 equality operator
 
bool operator!= (const Queue< TYPE > &rhs) const
 inequality operator
 
void Reserve (SizeT num)
 increase capacity to fit N more elements into the Dequeue (slow)
 
void Grow ()
 grow Dequeue by internal growing rules (slow)
 
SizeT Size () const
 returns number of elements in the Dequeue
 
SizeT Capacity () const
 returns allocation of elements in the Dequeue
 
bool IsEmpty () const
 return true if Dequeue is empty
 
void Clear ()
 remove all elements from the Dequeue
 
bool Contains (const TYPE &e) const
 return true if Dequeue contains element
 
void EraseIndex (const IndexT i)
 erase element at index (slow!!)
 
void Enqueue (const TYPE &e)
 add element to the back of the Dequeue, can trigger grow
 
void Enqueue (TYPE &&e)
 
TYPE Dequeue ()
 remove the element from the front of the Dequeue
 
TYPE & Peek () const
 access to element at front of Dequeue without removing it
 
- Static Protected Attributes inherited from Util::Queue< Util::KeyValuePair< PRITYPE, TYPE > >
static const SizeT MinGrowSize
 
static const SizeT MaxGrowSize
 

Constructor & Destructor Documentation

◆ SafePriorityQueue() [1/2]

template<class PRITYPE , class TYPE >
Threading::SafePriorityQueue< PRITYPE, TYPE >::SafePriorityQueue ( )

constructor

◆ SafePriorityQueue() [2/2]

template<class PRITYPE , class TYPE >
Threading::SafePriorityQueue< PRITYPE, TYPE >::SafePriorityQueue ( const SafePriorityQueue< PRITYPE, TYPE > & rhs)

copy constructor

Member Function Documentation

◆ Clear()

template<class PRITYPE , class TYPE >
void Threading::SafePriorityQueue< PRITYPE, TYPE >::Clear ( )

remove all elements from the queue

◆ Dequeue()

template<class PRITYPE , class TYPE >
TYPE Threading::SafePriorityQueue< PRITYPE, TYPE >::Dequeue ( )

remove the element from the front of the queue

◆ EraseMatchingElements()

template<class PRITYPE , class TYPE >
void Threading::SafePriorityQueue< PRITYPE, TYPE >::EraseMatchingElements ( const TYPE & e)

erase all matching elements

◆ Insert()

template<class PRITYPE , class TYPE >
void Threading::SafePriorityQueue< PRITYPE, TYPE >::Insert ( PRITYPE pri,
const TYPE & e )

add element to the back of the queue

◆ IsEmpty()

template<class PRITYPE , class TYPE >
bool Threading::SafePriorityQueue< PRITYPE, TYPE >::IsEmpty ( ) const

return true if queue is empty

◆ operator=()

template<class PRITYPE , class TYPE >
void Threading::SafePriorityQueue< PRITYPE, TYPE >::operator= ( const SafePriorityQueue< PRITYPE, TYPE > & rhs)

assignment operator

◆ Peek()

template<class PRITYPE , class TYPE >
TYPE Threading::SafePriorityQueue< PRITYPE, TYPE >::Peek ( ) const

get copy of element at front of queue without removing it

◆ Signal()

template<class PRITYPE , class TYPE >
void Threading::SafePriorityQueue< PRITYPE, TYPE >::Signal ( )

signal the internal event, so that Wait() will return

This signals the internal event object, on which Wait() may be waiting.

This method may be useful to wake up a thread waiting for events when it should stop.

◆ Size()

template<class PRITYPE , class TYPE >
SizeT Threading::SafePriorityQueue< PRITYPE, TYPE >::Size ( ) const

returns number of elements in the queue

◆ Wait()

template<class PRITYPE , class TYPE >
void Threading::SafePriorityQueue< PRITYPE, TYPE >::Wait ( )

wait until queue contains at least one element

Member Data Documentation

◆ criticalSection

template<class PRITYPE , class TYPE >
CriticalSection Threading::SafePriorityQueue< PRITYPE, TYPE >::criticalSection
protected

◆ enqueueEvent

template<class PRITYPE , class TYPE >
Event Threading::SafePriorityQueue< PRITYPE, TYPE >::enqueueEvent
protected

The documentation for this class was generated from the following file: