libDwm-0.6.0
Dwm::Pthread::Queue< _ValueType > Class Template Reference

This template provides inter-thread first-in first-out (FIFO) queueing. More...

#include <DwmPthreadQueue.hh>

Collaboration diagram for Dwm::Pthread::Queue< _ValueType >:

Public Member Functions

 Queue ()
 Constructor.
 
 ~Queue ()
 Destructor.
 
uint32_t MaxLength () const
 Returns the max length of the queue. More...
 
uint32_t MaxLength (uint32_t maxLength)
 Sets and returns the max length of the queue. More...
 
bool PushBack (const _ValueType &value)
 Inserts value on the back of the queue. More...
 
template<typename InputIterator >
uint32_t PushBack (InputIterator firstIter, InputIterator lastIter)
 
bool PushFront (const _ValueType &value)
 Inserts value on the front of the queue. More...
 
bool ConditionSignal ()
 Unblocks at least one thread waiting on the condition variable.
 
bool ConditionWait ()
 Waits for the condition variable to be signalled or broadcasted.
 
bool ConditionTimedWait (const struct timespec &timeToWait)
 Waits for the condition variable to be signalled or broadcasted for timeToWait to pass. More...
 
bool PopFront (_ValueType &value)
 Pops the entry from the front of the queue and stores it in value. More...
 
bool PopBack (_ValueType &value)
 Pops the entry from the back of the queue and stores it in value. More...
 
bool WaitForNotEmpty ()
 Blocks the calling thread until the queue contains at least one entry. More...
 
bool TimedWaitForNotEmpty (const struct timespec &timeToWait)
 Waits timeToWait for the queue to be non-empty. More...
 
bool Empty ()
 Returns true if the queue is empty, else returns false.
 
void RandomShuffle ()
 
uint32_t Copy (std::deque< _ValueType > &c)
 

Protected Member Functions

bool Lock ()
 
bool Unlock ()
 

Protected Attributes

uint32_t _maxLength
 
std::deque< _ValueType > _queue
 
Mutex _mutex
 
ConditionVariable _cv
 

Detailed Description

template<typename _ValueType>
class Dwm::Pthread::Queue< _ValueType >

This template provides inter-thread first-in first-out (FIFO) queueing.

A source thread may insert objects into the back of the queue using PushBack() while a sink thread pops objects from the front of the queue using PopFront(). A sink thread may use WaitForNotEmpty() to wait for entries to be added to the queue; the calling thread will be blocked until the queue is non-empty. A sink thread may also choose to use ConditionWait() and PopFront(), which allows a source to wake up the sink using ConditionBroadcast() or ConditionSignal() without pushing an entry into the queue.

Member Function Documentation

◆ ConditionTimedWait()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::ConditionTimedWait ( const struct timespec &  timeToWait)
inline

Waits for the condition variable to be signalled or broadcasted for timeToWait to pass.

Returns true if the condition variable was signalled or broadcasted, else returns false.

Here is the call graph for this function:

◆ MaxLength() [1/2]

template<typename _ValueType >
uint32_t Dwm::Pthread::Queue< _ValueType >::MaxLength ( ) const
inline

Returns the max length of the queue.

If 0, no maximum length will be enforced.

◆ MaxLength() [2/2]

template<typename _ValueType >
uint32_t Dwm::Pthread::Queue< _ValueType >::MaxLength ( uint32_t  maxLength)
inline

Sets and returns the max length of the queue.

If 0, no maximum length will be enforced.

◆ PopBack()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::PopBack ( _ValueType &  value)
inline

Pops the entry from the back of the queue and stores it in value.

Returns true on success, false on failure.

◆ PopFront()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::PopFront ( _ValueType &  value)
inline

Pops the entry from the front of the queue and stores it in value.

Returns true on success, false on failure.

◆ PushBack()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::PushBack ( const _ValueType &  value)
inline

Inserts value on the back of the queue.

Returns true on success, false on failure.

Here is the call graph for this function:

◆ PushFront()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::PushFront ( const _ValueType &  value)
inline

Inserts value on the front of the queue.

Returns true on success, false on failure.

Here is the call graph for this function:

◆ TimedWaitForNotEmpty()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::TimedWaitForNotEmpty ( const struct timespec &  timeToWait)
inline

Waits timeToWait for the queue to be non-empty.

Returns true if the queue is non-empty, else returns false.

Here is the call graph for this function:

◆ WaitForNotEmpty()

template<typename _ValueType >
bool Dwm::Pthread::Queue< _ValueType >::WaitForNotEmpty ( )
inline

Blocks the calling thread until the queue contains at least one entry.

Returns true on success, false on failure.

Here is the call graph for this function:

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