ucommon
Public Member Functions | Static Public Member Functions | Protected Attributes | Friends
ucommon::queue Class Reference

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

#include <containers.h>

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

Public Member Functions

ObjectProtocolfifo (timeout_t timeout=0)
 Get and remove last object posted to the queue.
size_t getCount (void)
 Get number of object points currently in the queue.
ObjectProtocollifo (timeout_t timeout=0)
 Get and remove first object posted to the queue.
ObjectProtocoloperator[] (unsigned pos)
ObjectProtocolpeek (unsigned offset=0)
 Examine pending existing object in queue.
bool post (ObjectProtocol *object, timeout_t timeout=0)
 Post an object into the queue by it's pointer.
 queue (mempager *pager=((void *) 0), 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.
bool remove (ObjectProtocol *object)
 Remove a specific object pointer for the queue.
 ~queue ()
 Destroy queue.

Static Public Member Functions

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

Protected Attributes

size_t limit

Friends

class member

Additional Inherited Members

- Protected Member Functions inherited from ucommon::OrderedIndex
void add (OrderedObject *ordered)
 Add an object into the ordered index.
LinkedObjectbegin (void)
 Return first object in list for iterators.
unsigned count (void)
 Count of objects this list manages.
LinkedObjectend (void)
 Return last object in list for iterators.
LinkedObjectfind (unsigned offset)
 Find a specific member in the ordered list.
LinkedObjectget (void)
 Get (pull) object off the list.
LinkedObjectgetIndexed (unsigned index)
 Get an indexed member from the ordered index.
LinkedObject ** index (void)
 Return a pointer to the head of the list.
virtual void lock_index (void)
 Used to synchronize lists managed by multiple threads.
LinkedObjectoperator* ()
 Return head object pointer.
void operator*= (OrderedObject *object)
 Add object to our list.
 OrderedIndex ()
 Create and initialize an empty index.
void purge (void)
 Purge the linked list and then set the index to empty.
void reset (void)
 Reset linked list to empty without purging.
virtual void unlock_index (void)
 Used to synchronize lists managed by multiple threads.
virtual ~OrderedIndex ()
 Destroy index.
- Static Protected Member Functions inherited from ucommon::Conditional
static void gettimeout (timeout_t timeout, struct timespec *hires)
 Convert a millisecond timeout into use for high resolution conditional timers.
static pthread_condattr_t * initializer (void)
 Support function for getting conditional attributes for realtime scheduling.

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.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 212 of file containers.h.

Constructor & Destructor Documentation

ucommon::queue::queue ( mempager pager = ((void *) 0),
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
pagerto use for internal member object or NULL to use heap.
numberof pointers that can be in the queue or 0 for unlimited. size limit.
ucommon::queue::~queue ( )

Destroy queue.

If no mempager is used, then frees heap.

Member Function Documentation

static size_t ucommon::queue::count ( queue queue)
inlinestatic

Convenience function to get count of objects in the queue.

Parameters
queueto count.
Returns
number of objects in the queue.

Definition at line 338 of file containers.h.

Here is the call graph for this function:

ObjectProtocol* ucommon::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
timeoutto wait if empty in milliseconds.
Returns
object from queue or NULL if empty and timed out.

Reimplemented in ucommon::queueof< T >.

static ObjectProtocol* ucommon::queue::fifo ( queue queue,
timeout_t  timeout = 0 
)
inlinestatic

Convenience function get first object from the queue.

Parameters
queueto get from.
timeoutto wait if empty.
Returns
first object or NULL if timed out empty.

Definition at line 321 of file containers.h.

Here is the call graph for this function:

size_t ucommon::queue::getCount ( void  )

Get number of object points currently in the queue.

Returns
number of objects in queue.
ObjectProtocol* ucommon::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
timeoutto wait if empty in milliseconds.
Returns
object from queue or NULL if empty and timed out.

Reimplemented in ucommon::queueof< T >.

static ObjectProtocol* ucommon::queue::lifo ( queue queue,
timeout_t  timeout = 0 
)
inlinestatic

Convenience function get last object from the queue.

Parameters
queueto get from.
timeoutto wait if empty.
Returns
last object or NULL if timed out empty.

Definition at line 330 of file containers.h.

Here is the call graph for this function:

ObjectProtocol* ucommon::queue::peek ( unsigned  offset = 0)

Examine pending existing object in queue.

Does not remove it.

Parameters
numberof elements back.
Returns
object in queue or NULL if invalid value.

Reimplemented in ucommon::queueof< T >.

bool ucommon::queue::post ( ObjectProtocol 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
objectto post.
timeoutto wait if queue is full in milliseconds.
Returns
true if object posted, false if queue full and timeout expired.
static bool ucommon::queue::post ( queue queue,
ObjectProtocol object,
timeout_t  timeout = 0 
)
inlinestatic

Convenience function to post object into the queue.

Parameters
queueto post into.
objectto post.
timeoutto wait if full.
Returns
true if posted, false if timed out while full.

Definition at line 312 of file containers.h.

Here is the call graph for this function:

bool ucommon::queue::remove ( ObjectProtocol 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
objectto remove.
Returns
true if object was removed, false if not found.
static bool ucommon::queue::remove ( queue queue,
ObjectProtocol object 
)
inlinestatic

Convenience function to remove an object from the queue.

Parameters
queueto remove object from.
objectto remove.
Returns
true if removed, false if not found.

Definition at line 302 of file containers.h.

Here is the call graph for this function:


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