Public Member Functions

FCam::TSQueue< T > Class Template Reference

Basic thread-safe consumer/producer queue. More...

#include <TSQueue.h>

List of all members.

Public Member Functions

void push (const T &val)
 Add a copy of item to the back of the queue.
void pop ()
 Remove the frontmost element from the queue.
void pushFront (const T &val)
 Add a copy of item to the front of the queue.
void popBack ()
 Remove the backmost element from the queue.
T & front ()
 Return a reference to the frontmost element of the queue.
T & back ()
 Return a reference to the backmost element of the queue.
bool empty () const
 Returns true if empty, false otherwise.
size_t size () const
 Returns the number of items in the queue.
bool wait (unsigned int timeout=0)
 Waits until there are entries in the queue.
pull ()
 Waits for the queue not to be empty, and then copies the frontmost item, then pops it from the queue and returns the element copy.
pullBack ()
 Pulls the backmost element off the queue.
bool tryPull (T *)
 Atomically either dequeue an item, or fail to do so.
locking_iterator begin ()
 Create an iterator referring to the front of the queue and locks the queue.
locking_iterator end ()
 Create an iterator referring to the end of the queue and locks the queue.
bool erase (TSQueue< T >::locking_iterator)
 Deletes an entry referred to by a locking_iterator.
void push (const T &val)
 Add a copy of item to the back of the queue.
void pop ()
 Remove the frontmost element from the queue.
void pushFront (const T &val)
 Add a copy of item to the front of the queue.
void popBack ()
 Remove the backmost element from the queue.
T & front ()
 Return a reference to the frontmost element of the queue.
T & back ()
 Return a reference to the backmost element of the queue.
bool empty () const
 Returns true if empty, false otherwise.
size_t size () const
 Returns the number of items in the queue.
bool wait (unsigned int timeout=0)
 Waits until there are entries in the queue.
pull ()
 Waits for the queue not to be empty, and then copies the frontmost item, then pops it from the queue and returns the element copy.
pullBack ()
 Pulls the backmost element off the queue.
bool tryPull (T *)
 Atomically either dequeue an item, or fail to do so.
locking_iterator begin ()
 Create an iterator referring to the front of the queue and locks the queue.
locking_iterator end ()
 Create an iterator referring to the end of the queue and locks the queue.
bool erase (TSQueue< T >::locking_iterator)
 Deletes an entry referred to by a locking_iterator.

Detailed Description

template<typename T>
class FCam::TSQueue< T >

Basic thread-safe consumer/producer queue.

Safe for multiple producers, but not for multiple consumers. The consumer will typically call wait(), pop(), front(), and pull, while producers mostly uses push().

Definition at line 33 of file TSQueue.h.


Member Function Documentation

template<typename T>
void FCam::TSQueue< T >::push ( const T &  val  ) 

Add a copy of item to the back of the queue.

Definition at line 205 of file TSQueue.h.

template<typename T >
void FCam::TSQueue< T >::pop (  ) 

Remove the frontmost element from the queue.

Definition at line 222 of file TSQueue.h.

template<typename T>
void FCam::TSQueue< T >::pushFront ( const T &  val  ) 

Add a copy of item to the front of the queue.

Definition at line 214 of file TSQueue.h.

template<typename T >
void FCam::TSQueue< T >::popBack (  ) 

Remove the backmost element from the queue.

Definition at line 231 of file TSQueue.h.

template<typename T >
T & FCam::TSQueue< T >::front (  ) 

Return a reference to the frontmost element of the queue.

Behavior not defined if size() == 0

Definition at line 240 of file TSQueue.h.

template<typename T >
T & FCam::TSQueue< T >::back (  ) 

Return a reference to the backmost element of the queue.

Behavior not defined if size() == 0

Definition at line 257 of file TSQueue.h.

template<typename T >
bool FCam::TSQueue< T >::empty (  )  const

Returns true if empty, false otherwise.

Definition at line 275 of file TSQueue.h.

template<typename T >
bool FCam::TSQueue< T >::wait ( unsigned int  timeout = 0  ) 

Waits until there are entries in the queue.

The optional timeout is in microseconds, zero means no timeout.

Definition at line 293 of file TSQueue.h.

template<typename T >
T FCam::TSQueue< T >::pull (  ) 

Waits for the queue not to be empty, and then copies the frontmost item, then pops it from the queue and returns the element copy.

A convenience function, which is somewhat inefficient if T is a large class (so use it on pointer-containing queues, mostly). This is the only safe way for multiple consumers to use the queue.

Definition at line 331 of file TSQueue.h.

template<typename T >
T FCam::TSQueue< T >::pullBack (  ) 

Pulls the backmost element off the queue.

Definition at line 343 of file TSQueue.h.

template<typename T>
bool FCam::TSQueue< T >::tryPull ( T *  ptr  ) 

Atomically either dequeue an item, or fail to do so.

Does not block. Returns whether it succeeded.

Definition at line 353 of file TSQueue.h.

template<typename T >
TSQueue< T >::locking_iterator FCam::TSQueue< T >::begin (  ) 

Create an iterator referring to the front of the queue and locks the queue.

Queue will remain locked until all the locked_iterators referring to it are destroyed.

Definition at line 375 of file TSQueue.h.

template<typename T >
TSQueue< T >::locking_iterator FCam::TSQueue< T >::end (  ) 

Create an iterator referring to the end of the queue and locks the queue.

Queue will remain locked until all the iterators referring to it are destroyed.

Definition at line 380 of file TSQueue.h.

template<typename T>
bool FCam::TSQueue< T >::erase ( TSQueue< T >::locking_iterator  li  ) 

Deletes an entry referred to by a locking_iterator.

Like a standard deque, if the entry erased is at the start or end of the queue, other iterators remain valid. Otherwise, all iterators and references are invalidated. Returns true if entry is successfully deleted. Failure can occur if some other thread(s) successfully reserved a queue entry/entries before the locking iterator claimed the queue.

Definition at line 385 of file TSQueue.h.

template<typename T>
void FCam::TSQueue< T >::push ( const T &  val  ) 

Add a copy of item to the back of the queue.

template<typename T>
void FCam::TSQueue< T >::pop (  ) 

Remove the frontmost element from the queue.

template<typename T>
void FCam::TSQueue< T >::pushFront ( const T &  val  ) 

Add a copy of item to the front of the queue.

template<typename T>
void FCam::TSQueue< T >::popBack (  ) 

Remove the backmost element from the queue.

template<typename T>
T& FCam::TSQueue< T >::front (  ) 

Return a reference to the frontmost element of the queue.

Behavior not defined if size() == 0

template<typename T>
T& FCam::TSQueue< T >::back (  ) 

Return a reference to the backmost element of the queue.

Behavior not defined if size() == 0

template<typename T>
bool FCam::TSQueue< T >::empty (  )  const

Returns true if empty, false otherwise.

template<typename T>
bool FCam::TSQueue< T >::wait ( unsigned int  timeout = 0  ) 

Waits until there are entries in the queue.

The optional timeout is in microseconds, zero means no timeout.

template<typename T>
T FCam::TSQueue< T >::pull (  ) 

Waits for the queue not to be empty, and then copies the frontmost item, then pops it from the queue and returns the element copy.

A convenience function, which is somewhat inefficient if T is a large class (so use it on pointer-containing queues, mostly). This is the only safe way for multiple consumers to use the queue.

template<typename T>
T FCam::TSQueue< T >::pullBack (  ) 

Pulls the backmost element off the queue.

template<typename T>
bool FCam::TSQueue< T >::tryPull ( T *   ) 

Atomically either dequeue an item, or fail to do so.

Does not block. Returns whether it succeeded.

template<typename T>
locking_iterator FCam::TSQueue< T >::begin (  ) 

Create an iterator referring to the front of the queue and locks the queue.

Queue will remain locked until all the locked_iterators referring to it are destroyed.

template<typename T>
locking_iterator FCam::TSQueue< T >::end (  ) 

Create an iterator referring to the end of the queue and locks the queue.

Queue will remain locked until all the iterators referring to it are destroyed.

template<typename T>
bool FCam::TSQueue< T >::erase ( TSQueue< T >::locking_iterator   ) 

Deletes an entry referred to by a locking_iterator.

Like a standard deque, if the entry erased is at the start or end of the queue, other iterators remain valid. Otherwise, all iterators and references are invalidated. Returns true if entry is successfully deleted. Failure can occur if some other thread(s) successfully reserved a queue entry/entries before the locking iterator claimed the queue.


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