S3FC project page S3FC home page

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

s3_spsc_fifo_queue Class Template Reference

This is a single producer, single consumer (SPSC), first in, first out (FIFO) queue. More...

#include <s3_spsc_fifo_queue.h>

Inheritance diagram for s3_spsc_fifo_queue:

Inheritance graph
[legend]
Collaboration diagram for s3_spsc_fifo_queue:

Collaboration graph
[legend]
List of all members.

Public Methods

 s3_spsc_fifo_queue (unsigned int n_buffer_size=5)
 Constructor for the FIFO queue. More...

virtual ~s3_spsc_fifo_queue ()
 Destructor for the FIFO queue. More...

bool empty () const
 Indicate if the queue is empty or not. More...

bool full () const
 Indicate if the queue is full or not. More...

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

T * open_input ()
 This method determine if there is an open slot to fill and return a pointer to one if there is. More...

T * nbl_open_input ()
 Non-blocking open input. More...

void close_input (const T *t=0)
 This method is called to signal that the producer has written all the data. More...

T * open_output ()
 This method determine if there is an open slot to receive data from, if there is a pointer to the data is returned. More...

T * nbl_open_output ()
 Non-blocking open output. More...

void close_output (const T *t=0)
 This method is called to signal that the consumer has read all the data. More...


Protected Methods

bool crit_empty () const
bool crit_full () const
T * crit_open_input ()
T * crit_open_output ()

Private Attributes

unsigned int buffer_size
 Internal variable that saves the buffer size. More...

T * buffer
 Pointer to the start of the circular buffer. More...

unsigned int c_size
 Internal variable that keeps track of the number of entries in the queue. More...

unsigned int input_index
 Index pointing to the next open slot for input. More...

unsigned int output_index
 Index pointing to the next available slot for output. More...

pthread_mutex_t access_lock_a
 Our access locking mutex. More...

pthread_mutex_t access_lock_p
 Our producer locking mutex. More...

pthread_mutex_t access_lock_c
 Our consumer locking mutex. More...

sem_t sem_read
 Semaphore that controls input access. More...

sem_t sem_write
 Semaphore that controlls output access. More...


Detailed Description

template<class T>
class s3_spsc_fifo_queue< T >

This is a single producer, single consumer (SPSC), first in, first out (FIFO) queue.

The FIFO is implemented using a circular array buffer.

Definition at line 49 of file s3_spsc_fifo_queue.h.


Constructor & Destructor Documentation

template<class T>
s3_spsc_fifo_queue< T >::s3_spsc_fifo_queue unsigned int    n_buffer_size = 5 [inline]
 

Constructor for the FIFO queue.

The constructor preallocate the required memory for the queue.

Parameters:
n_buffer_size  Specify the size of the buffer.

Definition at line 109 of file s3_spsc_fifo_queue.h.

References access_lock_a, access_lock_c, access_lock_p, buffer, buffer_size, c_size, input_index, output_index, sem_read, and sem_write.

template<class T>
virtual s3_spsc_fifo_queue< T >::~s3_spsc_fifo_queue   [inline, virtual]
 

Destructor for the FIFO queue.

It deallocate the buffer memory.

Definition at line 132 of file s3_spsc_fifo_queue.h.

References access_lock_a, access_lock_c, access_lock_p, buffer, sem_read, and sem_write.


Member Function Documentation

template<class T>
void s3_spsc_fifo_queue< T >::close_input const T *    t = 0 [inline, virtual]
 

This method is called to signal that the producer has written all the data.

The slot is now available for output.

Implements s3_inplace_fifo_base.

Definition at line 216 of file s3_spsc_fifo_queue.h.

References access_lock_p, buffer_size, c_size, input_index, s3_subscribable_fifo::notify_consumers, and sem_read.

template<class T>
void s3_spsc_fifo_queue< T >::close_output const T *    t = 0 [inline, virtual]
 

This method is called to signal that the consumer has read all the data.

The slot is now available for input again.

Implements s3_inplace_fifo_base.

Definition at line 265 of file s3_spsc_fifo_queue.h.

References access_lock_c, buffer_size, c_size, s3_subscribable_fifo::notify_producers, output_index, and sem_write.

template<class T>
bool s3_spsc_fifo_queue< T >::crit_empty   const [inline, protected]
 

Definition at line 77 of file s3_spsc_fifo_queue.h.

References c_size.

Referenced by empty, and nbl_open_output.

template<class T>
bool s3_spsc_fifo_queue< T >::crit_full   const [inline, protected]
 

Definition at line 82 of file s3_spsc_fifo_queue.h.

References buffer_size, and c_size.

Referenced by full, and nbl_open_input.

template<class T>
T* s3_spsc_fifo_queue< T >::crit_open_input   [inline, protected]
 

Definition at line 87 of file s3_spsc_fifo_queue.h.

References buffer, input_index, and sem_write.

Referenced by nbl_open_input, and open_input.

template<class T>
T* s3_spsc_fifo_queue< T >::crit_open_output   [inline, protected]
 

Definition at line 95 of file s3_spsc_fifo_queue.h.

References buffer, output_index, and sem_read.

Referenced by nbl_open_output, and open_output.

template<class T>
bool s3_spsc_fifo_queue< T >::empty   const [inline, virtual]
 

Indicate if the queue is empty or not.

Returns:
True if the queue is empty, false otherwise.

Implements s3_fifo_base.

Definition at line 147 of file s3_spsc_fifo_queue.h.

References access_lock_a, crit_empty, and NONCONST_MUTEXP.

template<class T>
bool s3_spsc_fifo_queue< T >::full   const [inline, virtual]
 

Indicate if the queue is full or not.

Returns:
True if the queue is empty, false otherwise.

Implements s3_fifo_base.

Definition at line 159 of file s3_spsc_fifo_queue.h.

References access_lock_a, crit_full, and NONCONST_MUTEXP.

template<class T>
T* s3_spsc_fifo_queue< T >::nbl_open_input   [inline, virtual]
 

Non-blocking open input.

Implements s3_inplace_fifo_base.

Definition at line 196 of file s3_spsc_fifo_queue.h.

References access_lock_p, crit_full, and crit_open_input.

template<class T>
T* s3_spsc_fifo_queue< T >::nbl_open_output   [inline, virtual]
 

Non-blocking open output.

Implements s3_inplace_fifo_base.

Definition at line 246 of file s3_spsc_fifo_queue.h.

References access_lock_p, crit_empty, and crit_open_output.

template<class T>
T* s3_spsc_fifo_queue< T >::open_input   [inline, virtual]
 

This method determine if there is an open slot to fill and return a pointer to one if there is.

The method will block if the circular buffer is full.

Returns:
Pointer to the next available slot.

Implements s3_inplace_fifo_base.

Definition at line 185 of file s3_spsc_fifo_queue.h.

References access_lock_p, and crit_open_input.

template<class T>
T* s3_spsc_fifo_queue< T >::open_output   [inline, virtual]
 

This method determine if there is an open slot to receive data from, if there is a pointer to the data is returned.

The method will block if the queue is empty.

Returns:
Pointer to the next available slot.

Implements s3_inplace_fifo_base.

Definition at line 235 of file s3_spsc_fifo_queue.h.

References access_lock_c, and crit_open_output.

template<class T>
unsigned int s3_spsc_fifo_queue< T >::size   const [inline, virtual]
 

Returns the number of entries in the queue.

Returns:
Entries in the queue.

Implements s3_fifo_base.

Definition at line 171 of file s3_spsc_fifo_queue.h.

References access_lock_a, c_size, and NONCONST_MUTEXP.


Member Data Documentation

template<class T>
pthread_mutex_t s3_spsc_fifo_queue::access_lock_a [private]
 

Our access locking mutex.

Definition at line 66 of file s3_spsc_fifo_queue.h.

Referenced by empty, full, s3_spsc_fifo_queue, size, and ~s3_spsc_fifo_queue.

template<class T>
pthread_mutex_t s3_spsc_fifo_queue::access_lock_c [private]
 

Our consumer locking mutex.

Definition at line 70 of file s3_spsc_fifo_queue.h.

Referenced by close_output, open_output, s3_spsc_fifo_queue, and ~s3_spsc_fifo_queue.

template<class T>
pthread_mutex_t s3_spsc_fifo_queue::access_lock_p [private]
 

Our producer locking mutex.

Definition at line 68 of file s3_spsc_fifo_queue.h.

Referenced by close_input, nbl_open_input, nbl_open_output, open_input, s3_spsc_fifo_queue, and ~s3_spsc_fifo_queue.

template<class T>
T* s3_spsc_fifo_queue::buffer [private]
 

Pointer to the start of the circular buffer.

Definition at line 55 of file s3_spsc_fifo_queue.h.

Referenced by crit_open_input, crit_open_output, s3_spsc_fifo_queue, and ~s3_spsc_fifo_queue.

template<class T>
unsigned int s3_spsc_fifo_queue::buffer_size [private]
 

Internal variable that saves the buffer size.

Definition at line 53 of file s3_spsc_fifo_queue.h.

Referenced by close_input, close_output, crit_full, and s3_spsc_fifo_queue.

template<class T>
unsigned int s3_spsc_fifo_queue::c_size [private]
 

Internal variable that keeps track of the number of entries in the queue.

Definition at line 60 of file s3_spsc_fifo_queue.h.

Referenced by close_input, close_output, crit_empty, crit_full, s3_spsc_fifo_queue, and size.

template<class T>
unsigned int s3_spsc_fifo_queue::input_index [private]
 

Index pointing to the next open slot for input.

Definition at line 62 of file s3_spsc_fifo_queue.h.

Referenced by close_input, crit_open_input, and s3_spsc_fifo_queue.

template<class T>
unsigned int s3_spsc_fifo_queue::output_index [private]
 

Index pointing to the next available slot for output.

Definition at line 64 of file s3_spsc_fifo_queue.h.

Referenced by close_output, crit_open_output, and s3_spsc_fifo_queue.

template<class T>
sem_t s3_spsc_fifo_queue::sem_read [private]
 

Semaphore that controls input access.

Definition at line 72 of file s3_spsc_fifo_queue.h.

Referenced by close_input, crit_open_output, s3_spsc_fifo_queue, and ~s3_spsc_fifo_queue.

template<class T>
sem_t s3_spsc_fifo_queue::sem_write [private]
 

Semaphore that controlls output access.

Definition at line 74 of file s3_spsc_fifo_queue.h.

Referenced by close_output, crit_open_input, s3_spsc_fifo_queue, and ~s3_spsc_fifo_queue.


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