ucc::queue Class Reference

Manage a thread-safe queue of objects through reference pointers. More...

#include <thread.h>

Inheritance diagram for ucc::queue:

Inheritance graph
[legend]
Collaboration diagram for ucc::queue:

Collaboration graph
[legend]

Public Member Functions

 queue (mempager *pager=NULL, size_t number=0)
 Create a queue that uses a memory pager for internally managed member objects for a specified maximum number of object pointers.
 ~queue ()
 Destroy queue.
bool remove (Object *object)
 Remove a specific object pointer for the queue.
bool post (Object *object, timeout_t timeout=0)
 Post an object into the queue by it's pointer.
Objectfifo (timeout_t timeout=0)
 Get and remove last object posted to the queue.
Objectlifo (timeout_t timeout=0)
 Get and remove first object posted to the queue.
size_t getCount (void)
 Get number of object points currently in the queue.

Static Public Member Functions

static bool remove (queue &queue, Object *object)
 Convenience function to remove an object from the queue.
static bool post (queue &queue, Object *object, timeout_t timeout=0)
 Convenience function to post object into the queue.
static Objectfifo (queue &queue, timeout_t timeout=0)
 Convenience function get first object from the queue.
static Objectlifo (queue &queue, timeout_t timeout=0)
 Convenience function get last object from the queue.
static size_t count (queue &queue)
 Convenience function to get count of objects in the queue.

Protected Attributes

size_t limit

Friends

class member

Detailed Description

Manage a thread-safe queue of objects through reference pointers.

This can be particularly interesting when used to enqueue/dequeue reference counted managed objects. Thread-safe access is managed through a conditional. Both lifo and fifo forms of queue access may be used. A pool of self-managed member objects are used to operate the queue. This queue is optimized for fifo access; while lifo is supported, it will be slow. If you need primarily lifo, you should use stack instead.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 1654 of file thread.h.


Constructor & Destructor Documentation

ucc::queue::queue ( mempager pager = NULL,
size_t  number = 0 
)

Create a queue that uses a memory pager for internally managed member objects for a specified maximum number of object pointers.

Parameters:
pager to use for internal member object or NULL to use heap.
number of pointers that can be in the queue or 0 for unlimited. size limit.

ucc::queue::~queue (  ) 

Destroy queue.

If no mempager is used, then frees heap.


Member Function Documentation

static size_t ucc::queue::count ( queue queue  )  [inline, static]

Convenience function to get count of objects in the queue.

Parameters:
queue to count.
Returns:
number of objects in the queue.

Definition at line 1773 of file thread.h.

Here is the call graph for this function:

static Object* ucc::queue::fifo ( queue queue,
timeout_t  timeout = 0 
) [inline, static]

Convenience function get first object from the queue.

Parameters:
queue to get from.
timeout to wait if empty.
Returns:
first object or NULL if timed out empty.

Definition at line 1756 of file thread.h.

Here is the call graph for this function:

Object* ucc::queue::fifo ( timeout_t  timeout = 0  ) 

Get and remove last object posted to the queue.

This can wait for a specified timeout of the queue is empty. The object is still retained and must be released or deleted by the receiving function.

Parameters:
timeout to wait if empty in milliseconds.
Returns:
object from queue or NULL if empty and timed out.

Reimplemented in ucc::queueof< T, P >.

size_t ucc::queue::getCount ( void   ) 

Get number of object points currently in the queue.

Returns:
number of objects in queue.

static Object* ucc::queue::lifo ( queue queue,
timeout_t  timeout = 0 
) [inline, static]

Convenience function get last object from the queue.

Parameters:
queue to get from.
timeout to wait if empty.
Returns:
last object or NULL if timed out empty.

Definition at line 1765 of file thread.h.

Here is the call graph for this function:

Object* ucc::queue::lifo ( timeout_t  timeout = 0  ) 

Get and remove first object posted to the queue.

This can wait for a specified timeout of the queue is empty. The object is still retained and must be released or deleted by the receiving function.

Parameters:
timeout to wait if empty in milliseconds.
Returns:
object from queue or NULL if empty and timed out.

Reimplemented in ucc::queueof< T, P >.

static bool ucc::queue::post ( queue queue,
Object object,
timeout_t  timeout = 0 
) [inline, static]

Convenience function to post object into the queue.

Parameters:
queue to post into.
object to post.
timeout to wait if full.
Returns:
true if posted, false if timed out while full.

Definition at line 1747 of file thread.h.

Here is the call graph for this function:

bool ucc::queue::post ( Object object,
timeout_t  timeout = 0 
)

Post an object into the queue by it's pointer.

This can wait for a specified timeout if the queue is full, for example, for another thread to remove an object pointer. This also retains the object.

Parameters:
object to post.
timeout to wait if queue is full in milliseconds.
Returns:
true if object posted, false if queue full and timeout expired.

static bool ucc::queue::remove ( queue queue,
Object object 
) [inline, static]

Convenience function to remove an object from the queue.

Parameters:
queue to remove object from.
object to remove.
Returns:
true if removed, false if not found.

Definition at line 1737 of file thread.h.

bool ucc::queue::remove ( Object object  ) 

Remove a specific object pointer for the queue.

This can remove a member from any location in the queue, whether beginning, end, or somewhere in the middle. This also releases the object.

Parameters:
object to remove.
Returns:
true if object was removed, false if not found.


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

Generated on Mon Jul 27 21:11:23 2009 for UCommon by  doxygen 1.5.9