S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_growable_fifo_queue Class Template Reference

Thread safe multi-consumer/multi-producer FIFO queue template. More...

#include <s3_growable_fifo_queue.h>

Inheritance diagram for s3_growable_fifo_queue:

Inheritance graph
[legend]
Collaboration diagram for s3_growable_fifo_queue:

Collaboration graph
[legend]
List of all members.

Public Methods

 s3_growable_fifo_queue (int n_max_size=-1)
 Constructor just needs to set up the mutex. More...

virtual ~s3_growable_fifo_queue ()
 Clean up. More...

void push (const T &t)
 Wrapper around STL queue push that just locks the mutex. More...

pop ()
 Remove oldest entry, blocking if the queue is empty. More...

bool empty () const
 Check if queue is empty. More...

bool full () const
 Returns true if the queue is full. More...

unsigned int size () const
 Returns the number of elements in the queue. More...


Private Attributes

pthread_mutex_t mutex
 If you hold this mutex, you got the queue. More...

pthread_mutexattr_t m_attr
 Sets up the kind of mutex we need. More...

pthread_cond_t cond_not_empty
 Signal this condition if the queue is no longer empty. More...

pthread_cond_t cond_not_full
 Condition to be signalled on a pop() to indicate that there is at least one opening in the queue. More...

std::queue< T > q
 STL container for the data. More...

int max_size
 Maximum number of elements in the queue. More...


Detailed Description

template<typename T>
class s3_growable_fifo_queue< T >

Thread safe multi-consumer/multi-producer FIFO queue template.

This class wraps around the STL queue class and provides templated thread safe queues that are used to queue external messages and commands for display and execution. Any number of threads can push and pop data to and from this class in a safe manner.

Author:
David Weber <weber@stonethree.com>

Definition at line 50 of file s3_growable_fifo_queue.h.


Constructor & Destructor Documentation

template<typename T>
s3_growable_fifo_queue< T >::s3_growable_fifo_queue int    n_max_size = -1 [inline]
 

Constructor just needs to set up the mutex.

It can optionally limit the maximum size of the queue if your consumer is slower than your producer.

Parameters:
a_max_size  The maximum number of elements allowed in the queue.

Definition at line 89 of file s3_growable_fifo_queue.h.

template<typename T>
virtual s3_growable_fifo_queue< T >::~s3_growable_fifo_queue   [inline, virtual]
 

Clean up.

Definition at line 99 of file s3_growable_fifo_queue.h.


Member Function Documentation

template<typename T>
bool s3_growable_fifo_queue< T >::empty   const [inline, virtual]
 

Check if queue is empty.

Just checks if the queue is empty with locks.

Returns:
Boolean true if the queue is empty, false otherwise.

Implements s3_fifo_base.

Definition at line 181 of file s3_growable_fifo_queue.h.

template<typename T>
bool s3_growable_fifo_queue< T >::full   const [inline, virtual]
 

Returns true if the queue is full.

Returns:
Boolean true if the queue is full, false otherwise.

Implements s3_fifo_base.

Definition at line 194 of file s3_growable_fifo_queue.h.

template<typename T>
T s3_growable_fifo_queue< T >::pop   [inline, virtual]
 

Remove oldest entry, blocking if the queue is empty.

If you want a non-blocking queue, test if the queue is empty prior to calling pop(). Note that this combines the front() and pop() commands needed to read and remove the oldest entry in the queue. It also does the necessary locking of the mutex. The calling thread will block until something arrives in the queue.

Returns:
The oldest entry in the queue.

Implements s3_fifo_base.

Definition at line 146 of file s3_growable_fifo_queue.h.

template<typename T>
void s3_growable_fifo_queue< T >::push const T &    t [inline, virtual]
 

Wrapper around STL queue push that just locks the mutex.

The push will block if the queue is full, and wait until pop() has been called at least once. This call will also release any thread that is blocking on an empty queue.

Parameters:
o  The object to be inserted into the end of the queue.

Implements s3_fifo_base.

Definition at line 114 of file s3_growable_fifo_queue.h.

template<typename T>
unsigned int s3_growable_fifo_queue< T >::size   const [inline, virtual]
 

Returns the number of elements in the queue.

Implements s3_fifo_base.

Definition at line 206 of file s3_growable_fifo_queue.h.


Member Data Documentation

template<typename T>
pthread_cond_t s3_growable_fifo_queue::cond_not_empty [private]
 

Signal this condition if the queue is no longer empty.

This allows the queue to block until something pitches from the sender.

Definition at line 64 of file s3_growable_fifo_queue.h.

Referenced by s3_growable_fifo_queue< s3_txport_event >::pop, s3_growable_fifo_queue< s3_txport_event >::push, s3_growable_fifo_queue< s3_txport_event >::s3_growable_fifo_queue, and s3_growable_fifo_queue< s3_txport_event >::~s3_growable_fifo_queue.

template<typename T>
pthread_cond_t s3_growable_fifo_queue::cond_not_full [private]
 

Condition to be signalled on a pop() to indicate that there is at least one opening in the queue.

Definition at line 70 of file s3_growable_fifo_queue.h.

Referenced by s3_growable_fifo_queue< s3_txport_event >::pop, s3_growable_fifo_queue< s3_txport_event >::push, s3_growable_fifo_queue< s3_txport_event >::s3_growable_fifo_queue, and s3_growable_fifo_queue< s3_txport_event >::~s3_growable_fifo_queue.

template<typename T>
pthread_mutexattr_t s3_growable_fifo_queue::m_attr [private]
 

Sets up the kind of mutex we need.

Definition at line 57 of file s3_growable_fifo_queue.h.

Referenced by s3_growable_fifo_queue< s3_txport_event >::s3_growable_fifo_queue, and s3_growable_fifo_queue< s3_txport_event >::~s3_growable_fifo_queue.

template<typename T>
int s3_growable_fifo_queue::max_size [private]
 

Maximum number of elements in the queue.

Setting this to a non-zero value limits the size of the queue. The push() method will block until something reads from the queue.

Definition at line 80 of file s3_growable_fifo_queue.h.

Referenced by s3_growable_fifo_queue< s3_txport_event >::full, s3_growable_fifo_queue< s3_txport_event >::pop, s3_growable_fifo_queue< s3_txport_event >::push, and s3_growable_fifo_queue< s3_txport_event >::s3_growable_fifo_queue.

template<typename T>
pthread_mutex_t s3_growable_fifo_queue::mutex [private]
 

If you hold this mutex, you got the queue.

Definition at line 54 of file s3_growable_fifo_queue.h.

Referenced by s3_growable_fifo_queue< s3_txport_event >::empty, s3_growable_fifo_queue< s3_txport_event >::full, s3_growable_fifo_queue< s3_txport_event >::pop, s3_growable_fifo_queue< s3_txport_event >::push, s3_growable_fifo_queue< s3_txport_event >::s3_growable_fifo_queue, s3_growable_fifo_queue< s3_txport_event >::size, and s3_growable_fifo_queue< s3_txport_event >::~s3_growable_fifo_queue.

template<typename T>
std::queue<T> s3_growable_fifo_queue::q [private]
 

STL container for the data.

Definition at line 73 of file s3_growable_fifo_queue.h.

Referenced by s3_growable_fifo_queue< s3_txport_event >::empty, s3_growable_fifo_queue< s3_txport_event >::full, s3_growable_fifo_queue< s3_txport_event >::pop, s3_growable_fifo_queue< s3_txport_event >::push, and s3_growable_fifo_queue< s3_txport_event >::size.


The documentation for this class was generated from the following file:
Send comments to: s3fc@stonethree.com SourceForge Logo