Nebula
Loading...
Searching...
No Matches
Threading::SafeQueue< TYPE > Class Template Reference

#include <safequeue.h>

Detailed Description

template<class TYPE>
class Threading::SafeQueue< TYPE >

Thread-safe version of Util::Queue.

The SafeQueue is normally configured to signal an internal Event object when an element is enqueued, so that a worker-thread can wait for new elements to arrive. This is the default behaviour. This doesn't make sense for a continously running thread (i.e. a rendering thread), thus this behaviour can be disabled using the SetSignalOnEnqueueEnabled(). In this case, the Enqueue() method won't signal the internal event, and the Wait() method will return immediately without ever waiting.

Public Member Functions

 SafeQueue ()
 constructor
 
 SafeQueue (const SafeQueue< TYPE > &rhs)
 copy constructor
 
void operator= (const SafeQueue< TYPE > &rhs)
 assignment operator
 
void SetSignalOnEnqueueEnabled (bool b)
 enable/disable signalling on Enqueue() (default is enabled)
 
bool IsSignalOnEnqueueEnabled () const
 return signalling-on-Enqueue() flag
 
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 Enqueue (const TYPE &e)
 add element to the back of the queue
 
void Enqueue (TYPE &&e)
 
void EnqueueArray (const Util::Array< TYPE > &a)
 enqueue an array of elements
 
TYPE Dequeue ()
 remove the element from the front of the queue
 
void DequeueAll (Util::Array< TYPE > &outArray)
 dequeue all events (only requires one lock)
 
TYPE Peek () const
 access to element at front of queue without removing it
 
void Wait ()
 wait until queue contains at least one element
 
void WaitTimeout (int ms)
 wait until queue contains at least one element, or time-out happens
 
void Signal ()
 signal the internal event, so that Wait() will return
 
void EraseMatchingElements (const TYPE &e)
 erase all matching elements
 

Protected Attributes

CriticalSection criticalSection
 
Event enqueueEvent
 
bool signalOnEnqueueEnabled
 
Util::Queue< TYPE > queue
 

Constructor & Destructor Documentation

◆ SafeQueue() [1/2]

template<class TYPE >
Threading::SafeQueue< TYPE >::SafeQueue ( )

constructor

◆ SafeQueue() [2/2]

template<class TYPE >
Threading::SafeQueue< TYPE >::SafeQueue ( const SafeQueue< TYPE > & rhs)

copy constructor

Member Function Documentation

◆ Clear()

template<class TYPE >
void Threading::SafeQueue< TYPE >::Clear ( )

remove all elements from the queue

◆ Dequeue()

template<class TYPE >
TYPE Threading::SafeQueue< TYPE >::Dequeue ( )

remove the element from the front of the queue

◆ DequeueAll()

template<class TYPE >
void Threading::SafeQueue< TYPE >::DequeueAll ( Util::Array< TYPE > & outArray)

dequeue all events (only requires one lock)

◆ Enqueue() [1/2]

template<class TYPE >
void Threading::SafeQueue< TYPE >::Enqueue ( const TYPE & e)

add element to the back of the queue

◆ Enqueue() [2/2]

template<class TYPE >
void Threading::SafeQueue< TYPE >::Enqueue ( TYPE && e)

◆ EnqueueArray()

template<class TYPE >
void Threading::SafeQueue< TYPE >::EnqueueArray ( const Util::Array< TYPE > & a)

enqueue an array of elements

◆ EraseMatchingElements()

template<class TYPE >
void Threading::SafeQueue< TYPE >::EraseMatchingElements ( const TYPE & e)

erase all matching elements

◆ IsEmpty()

template<class TYPE >
bool Threading::SafeQueue< TYPE >::IsEmpty ( ) const

return true if queue is empty

◆ IsSignalOnEnqueueEnabled()

template<class TYPE >
bool Threading::SafeQueue< TYPE >::IsSignalOnEnqueueEnabled ( ) const

return signalling-on-Enqueue() flag

◆ operator=()

template<class TYPE >
void Threading::SafeQueue< TYPE >::operator= ( const SafeQueue< TYPE > & rhs)

assignment operator

◆ Peek()

template<class TYPE >
TYPE Threading::SafeQueue< TYPE >::Peek ( ) const

access to element at front of queue without removing it

◆ SetSignalOnEnqueueEnabled()

template<class TYPE >
void Threading::SafeQueue< TYPE >::SetSignalOnEnqueueEnabled ( bool b)

enable/disable signalling on Enqueue() (default is enabled)

◆ Signal()

template<class TYPE >
void Threading::SafeQueue< 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 TYPE >
SizeT Threading::SafeQueue< TYPE >::Size ( ) const

returns number of elements in the queue

◆ Wait()

template<class TYPE >
void Threading::SafeQueue< TYPE >::Wait ( )

wait until queue contains at least one element

◆ WaitTimeout()

template<class TYPE >
void Threading::SafeQueue< TYPE >::WaitTimeout ( int ms)

wait until queue contains at least one element, or time-out happens

Member Data Documentation

◆ criticalSection

template<class TYPE >
CriticalSection Threading::SafeQueue< TYPE >::criticalSection
protected

◆ enqueueEvent

template<class TYPE >
Event Threading::SafeQueue< TYPE >::enqueueEvent
protected

◆ queue

template<class TYPE >
Util::Queue<TYPE> Threading::SafeQueue< TYPE >::queue
protected

◆ signalOnEnqueueEnabled

template<class TYPE >
bool Threading::SafeQueue< TYPE >::signalOnEnqueueEnabled
protected

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