libDwm-0.9.45
Dwm::Thread::Queue< _ValueType > Class Template Reference

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

#include <DwmThreadQueue.hh>

Public Member Functions

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

Protected Member Functions

void Lock ()
 
void Unlock ()
 

Protected Attributes

uint32_t _maxLength
 
std::deque< _ValueType > _queue
 
std::mutex _mutex
 
std::atomic< bool > _signalled
 
std::unique_lock< std::mutex > _lock
 
std::condition_variable _cv
 

Detailed Description

template<typename _ValueType>
class Dwm::Thread::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 >
template<class Rep , class Period >
bool Dwm::Thread::Queue< _ValueType >::ConditionTimedWait ( const std::chrono::duration< Rep, Period > & 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.

◆ Copy()

template<typename _ValueType >
uint32_t Dwm::Thread::Queue< _ValueType >::Copy ( std::deque< _ValueType > & c)
inline

Copies the contents of the queue to c.

Returns the number of elements copied. Note that c will always be cleared before elements are copied. Hence if there are no entries in the queue, c will be empty on return.

◆ MaxLength() [1/2]

template<typename _ValueType >
uint32_t Dwm::Thread::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::Thread::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::Thread::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::Thread::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() [1/3]

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

Inserts value on the back of the queue.

Returns true on success, false on failure.

◆ PushBack() [2/3]

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

Inserts value on the back of the queue.

Returns true on success, false on failure.

◆ PushBack() [3/3]

template<typename _ValueType >
template<typename InputIterator >
uint32_t Dwm::Thread::Queue< _ValueType >::PushBack ( InputIterator firstIter,
InputIterator lastIter )
inline

Inserts the values from firstIter to lastIter on the back of the queue.

Note that lastIter is excluded, i.e. the range of entries inserted is [firstIter,lastIter). Returns the number of entries inserted.

◆ PushFront()

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

Inserts value on the front of the queue.

Returns true on success, false on failure.

◆ Swap()

template<typename _ValueType >
uint32_t Dwm::Thread::Queue< _ValueType >::Swap ( std::deque< _ValueType > & c)
inline

This member is a simple optimization for fetching the contents of the queue.

It swaps the encapsulated queue with c, then clears the contents of the encapsulated queue. It returns the number of entries in c after the swap, i.e. the number of entries that were in the encapsulated queue before this member was called.

◆ TimedWaitForNotEmpty()

template<typename _ValueType >
template<class Rep , class Period >
bool Dwm::Thread::Queue< _ValueType >::TimedWaitForNotEmpty ( const std::chrono::duration< Rep, Period > & timeToWait)
inline

Waits timeToWait for the queue to be non-empty.

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

◆ WaitForNotEmpty()

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

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

Returns true on success, false on failure.


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