LDK::LocklessQueue< T > Class Template Reference
[Containers]

A threadsafe lockless queue template. More...

#include <LDK/LocklessQueue.h>


Public Member Functions

 LocklessQueue (size_t size)
 ~LocklessQueue ()
void enqueue (const T &msg)
void enqueue (const T *msg)
void dequeue (T &msg)
void dequeue (T *msg)
bool full () const
bool empty () const
const T * peek () const
void clear ()

Data Structures

struct  QType


Detailed Description

template<class T>
class LDK::LocklessQueue< T >

Will be thread safe providing there is only one reader thread and one writer thread. Based on the lockless queue in the PortMidi library http://www-2.cs.cmu.edu/~music/portmusic/

WARNING: simply performs bitwise copy, does not use copy constructors or assignment operators, so not a deep copy. Care will be needed for objects containing pointers (generally a "thou shalt not"). Deep copies would be completely unsafe in multithreaded progs.

The template parameter T is the type of the message. This queue can only hold one size message.

See also:
Thread

Mutex

Lock

Definition at line 62 of file LocklessQueue.h.


Constructor & Destructor Documentation

template<class T>
LDK::LocklessQueue< T >::LocklessQueue ( size_t  size  )  [inline]

Constructor.

Parameters:
size the number of items the queue can hold
Exceptions:
BadAllocError If there is not enough memory for the queue.

Definition at line 105 of file LocklessQueue.h.


Member Function Documentation

template<class T>
void LDK::LocklessQueue< T >::enqueue ( const T &  msg  )  [inline]

Push a message onto the head of the queue. Actually performs a bitwise copy of msg into the queue.

Parameters:
msg A reference to the message to push.
Exceptions:
LengthError if the queue is full.

Definition at line 121 of file LocklessQueue.h.

References LDK_LENGTH_ERROR.

Referenced by LDK::LocklessQueue< T >::enqueue().

template<class T>
void LDK::LocklessQueue< T >::enqueue ( const T *  msg  )  [inline]

Push a message onto the head of the queue. Actually performs a bitwise copy of msg into the queue.

Parameters:
msg A pointer to the message to push.
Exceptions:
LengthError if the queue is full.

Definition at line 140 of file LocklessQueue.h.

References LDK::LocklessQueue< T >::enqueue().

Here is the call graph for this function:

template<class T>
void LDK::LocklessQueue< T >::dequeue ( T &  msg  )  [inline]

Pops a message from the tail of the queue. Actually performs a bitwise copy of the message in the queue.

Parameters:
msg A reference to the message to copy into.
Exceptions:
LengthError if the queue is empty.

Definition at line 149 of file LocklessQueue.h.

References LDK_LENGTH_ERROR.

Referenced by LDK::LocklessQueue< T >::dequeue().

template<class T>
void LDK::LocklessQueue< T >::dequeue ( T *  msg  )  [inline]

Pops a message from the tail of the queue. Actually performs a bitwise copy of the message in the queue.

Parameters:
msg A pointer to the message to copy into.
Exceptions:
LengthError if the queue is empty.

Definition at line 172 of file LocklessQueue.h.

References LDK::LocklessQueue< T >::dequeue().

Here is the call graph for this function:

template<class T>
bool LDK::LocklessQueue< T >::full (  )  const [inline]

Tests if the queue is full.

Returns:
true if full, else false.

Definition at line 179 of file LocklessQueue.h.

template<class T>
bool LDK::LocklessQueue< T >::empty (  )  const [inline]

Tests if the queue is empty.

Returns:
true if empty, else false.

Definition at line 189 of file LocklessQueue.h.

template<class T>
const T* LDK::LocklessQueue< T >::peek (  )  const [inline]

Get the first event in the queue without removing it.

Returns:
a pointer to the message, or NULL if the queue is empty

Definition at line 196 of file LocklessQueue.h.

References NULL.


The documentation for this class was generated from the following file:
Generated on Fri Aug 17 18:32:27 2007 for LDK by  doxygen 1.5.1