shm_queue< T > Class Template Reference

Simple template queue class definition. More...

#include <shm_queue.h>

Collaboration diagram for shm_queue< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 shm_queue (shm_allocator &allocator, const size_t maxsize)
 shm_queue (shm_allocator &allocator)
 ~shm_queue ()
void * operator new (size_t s, shm_allocator &a)
void operator delete (void *p, shm_allocator &a)
void push (shm_ptr< T > obj)
shm_ptr< T > pop ()
void lock_head ()
void unlock_head ()
void lock_tail ()
void unlock_tail ()
size_t size () const

Private Member Functions

 shm_queue (const shm_queue &copy)
shm_queueoperator= (const shm_queue &rhs)

Private Attributes

size_t MaxQueueSize
shm_ptr< shm_queue_header<
T > > 
shm_header
shm_allocatora
const shm_segmentseg

Detailed Description

template<typename T>
class shm_queue< T >

Simple template queue class definition.

This queue template can be used for basic FIFO operation. It uses the shared memory segment allocator to construct queue nodes and POSIX mutex for locks and condition variables.

The shm_queue_header and the shm_queue_node classes reside in shared memory.

Definition at line 135 of file shm_queue.h.


Constructor & Destructor Documentation

template<typename T>
shm_queue< T >::shm_queue ( shm_allocator allocator,
const size_t  maxsize 
) [inline]

constructor requires an allocator and a maximum queue depth.

Parameters:
allocator used to obtain memory
maxsize number of elements in this queue

Definition at line 145 of file shm_queue.h.

References shm_queue< T >::a, shm_ptr< T >::reset(), shm_queue< T >::seg, and shm_queue< T >::shm_header.

Here is the call graph for this function:

template<typename T>
shm_queue< T >::shm_queue ( shm_allocator allocator  )  [inline]

constructor requires an allocator

Parameters:
allocator used to obtain memory

Definition at line 159 of file shm_queue.h.

References shm_queue< T >::a, shm_segment::get_base(), shm_allocator::get_overhead(), shm_ptr< T >::reset(), shm_queue< T >::seg, and shm_queue< T >::shm_header.

Here is the call graph for this function:

template<typename T>
shm_queue< T >::~shm_queue (  )  [inline]

Definition at line 171 of file shm_queue.h.

template<typename T>
shm_queue< T >::shm_queue ( const shm_queue< T > &  copy  )  [private]


Member Function Documentation

template<typename T>
void* shm_queue< T >::operator new ( size_t  s,
shm_allocator a 
) [inline]

Definition at line 173 of file shm_queue.h.

References shm_queue< T >::a, and shm_allocator::alloc().

Here is the call graph for this function:

template<typename T>
void shm_queue< T >::operator delete ( void *  p,
shm_allocator a 
) [inline]

Definition at line 177 of file shm_queue.h.

References shm_queue< T >::a, and shm_allocator::free().

Here is the call graph for this function:

template<typename T>
void shm_queue< T >::push ( shm_ptr< T >  obj  ) 

push a node into the queue

Obtain queue head lock and insert object into the front of the queue. If the queue was empty unlock the tail.

Parameters:
obj shared segment pointer of object to enqueue
TODO: if queue is full wait until an element is popped

Definition at line 249 of file shm_queue.h.

References shm_queue< T >::a, shm_queue_node< T >::data, shm_ptr< T >::get(), shm_segment::get_base(), shm_allocator::get_overhead(), shm_queue_header< T >::head, shm_queue_header< T >::head_lock, shm_queue_node< T >::next, shm_ptr< T >::off(), shm_queue_node< T >::prev, shm_queue_header< T >::ready_for_pop, shm_ptr< T >::reset(), shm_queue< T >::seg, shm_queue_header< T >::size, and shm_queue_header< T >::tail.

Referenced by main().

Here is the call graph for this function:

template<typename T>
shm_ptr< T > shm_queue< T >::pop (  ) 

pop a node from the queue

Obtain queue tail lock and remove object from the back of the queue. If the resulting queue is empty lock the tail and set head to null.

Returns:
obj shared segment pointer of object dequeued

Definition at line 302 of file shm_queue.h.

References shm_queue< T >::a, shm_queue_node< T >::data, shm_ptr< T >::get(), shm_segment::get_base(), shm_allocator::get_overhead(), shm_queue_header< T >::head, shm_ptr< T >::off(), shm_queue_node< T >::prev, shm_queue_header< T >::ready_for_pop, shm_queue_header< T >::ready_for_push, shm_queue< T >::seg, shm_ptr< T >::set(), shm_queue_header< T >::size, shm_queue_header< T >::tail, shm_queue_header< T >::tail_lock, and scoped_lock::wait().

Referenced by main().

Here is the call graph for this function:

template<typename T>
void shm_queue< T >::lock_head (  )  [inline]

lock the head of the queue

Definition at line 187 of file shm_queue.h.

References shm_ptr< T >::get(), shm_queue_header< T >::head_lock, shm_queue< T >::seg, and shm_queue< T >::shm_header.

Here is the call graph for this function:

template<typename T>
void shm_queue< T >::unlock_head (  )  [inline]

unlock the head of the queue

Definition at line 195 of file shm_queue.h.

References shm_ptr< T >::get(), shm_queue_header< T >::head_lock, shm_queue< T >::seg, and shm_queue< T >::shm_header.

Here is the call graph for this function:

template<typename T>
void shm_queue< T >::lock_tail (  )  [inline]

lock the tail of the queue

Definition at line 203 of file shm_queue.h.

References shm_ptr< T >::get(), shm_queue< T >::seg, shm_queue< T >::shm_header, and shm_queue_header< T >::tail_lock.

Here is the call graph for this function:

template<typename T>
void shm_queue< T >::unlock_tail (  )  [inline]

lock the tail of the queue

Definition at line 211 of file shm_queue.h.

References shm_ptr< T >::get(), shm_queue< T >::seg, shm_queue< T >::shm_header, and shm_queue_header< T >::tail_lock.

Here is the call graph for this function:

template<typename T>
size_t shm_queue< T >::size (  )  const [inline]

get the size of the queue

Definition at line 219 of file shm_queue.h.

References shm_ptr< T >::get(), shm_queue< T >::seg, shm_queue< T >::shm_header, and shm_queue_header< T >::size.

Referenced by main().

Here is the call graph for this function:

template<typename T>
shm_queue& shm_queue< T >::operator= ( const shm_queue< T > &  rhs  )  [private]


Member Data Documentation

template<typename T>
size_t shm_queue< T >::MaxQueueSize [private]

Definition at line 225 of file shm_queue.h.

template<typename T>
shm_ptr< shm_queue_header<T> > shm_queue< T >::shm_header [private]

Definition at line 227 of file shm_queue.h.

Referenced by shm_queue< T >::lock_head(), shm_queue< T >::lock_tail(), shm_queue< T >::shm_queue(), shm_queue< T >::size(), shm_queue< T >::unlock_head(), and shm_queue< T >::unlock_tail().

template<typename T>
shm_allocator& shm_queue< T >::a [private]

Definition at line 229 of file shm_queue.h.

Referenced by shm_queue< T >::operator delete(), shm_queue< T >::operator new(), shm_queue< T >::pop(), shm_queue< T >::push(), and shm_queue< T >::shm_queue().

template<typename T>
const shm_segment& shm_queue< T >::seg [private]

Definition at line 230 of file shm_queue.h.

Referenced by shm_queue< T >::lock_head(), shm_queue< T >::lock_tail(), shm_queue< T >::pop(), shm_queue< T >::push(), shm_queue< T >::shm_queue(), shm_queue< T >::size(), shm_queue< T >::unlock_head(), and shm_queue< T >::unlock_tail().


The documentation for this class was generated from the following file:
Project shmq hosted by   SourceForge.net
Documentation generated on Sat Sep 2 10:07:40 2006 for shmq by   doxygen.org 1.4.6