CObject
CCThreadedQueue Struct Reference

Thread safe wrapper for queues derived from the CIQueue interface. More...

#include <CCThreadedQueue.h>

Public Member Functions

const struct CCThreadedQueue_VTableCCThreadedQueue_VTable_Key ()
 
CError CCThreadedQueue (struct CCThreadedQueue *self, struct CIQueue *backbone)
 
CCTQueueError CCThreadedQueue_Insert (struct CCThreadedQueue *self, const void *element, COS_Timemsec blockTime)
 
CCTQueueError CCThreadedQueue_Remove (struct CCThreadedQueue *self, void *element, COS_Timemsec blockTime)
 
CCTQueueError CCThreadedQueue_Peek (struct CCThreadedQueue *self, void *element, COS_Timemsec blockTime)
 
size_t CCThreadedQueue_MaxSize (struct CCThreadedQueue *self)
 
void CCThreadedQueue_Clear (struct CCThreadedQueue *self)
 

Data Fields

struct CObject cobject
 
struct {
   struct CIQueue *   backbone
 
_
 

Detailed Description

Thread safe wrapper for queues derived from the CIQueue interface. This class will use a pointer to strongly aggregate a CIQueue object and wrap it's methods to make them threadsafe. To that effect, it requires an already constructed queue at construction time. Destroying the CCThreadedQueue object will result in the destruction of the aggregate CIQueue object.

struct CCThreadedQueue queue;
struct CCArrayQueue queueBackbone;
CCArrayQueue(&queueBackbone, sizeof(char), 3);
CCThreadedQueue(&queue, &queueBackbone->cIQueue);
char test = 'h'
CCThreadedQueue_Insert(&queue, &test, COS_BLOCK_FOREVER);
char test_peek;
CCThreadedQueue_Peek(&queue, &test_peek, COS_BLOCK_FOREVER);
if( test_peek == 'h' ) {
printf("success!");
}
CDestroy(&queue);
Attention
Destroying a CCThreadQueue object will result in the destruction of the aggregate CIQueue object. See constructor, CCThreadedQueue(), for more details.
This class does not have any virtual methods. All class methods are not virtual.

Constructor & Destructor Documentation

CError CCThreadedQueue ( struct CCThreadedQueue self,
struct CIQueue backbone 
)
Class Constructor
Parameters
selfThe instance of struct CCThreadedQueue to construct.
backboneAn instance of a CIQueue object. This will be used as the backbone for all queue operations. Note, when the destructor is called, this object will also be destroyed.
Returns
CIQUEUE_OK on successful construction.

Member Function Documentation

void CCThreadedQueue_Clear ( struct CCThreadedQueue self)

Reset the queue to having zero elements in it. All data copied into the queue is lost.

Parameters
selfThe queue.
CCTQueueError CCThreadedQueue_Insert ( struct CCThreadedQueue self,
const void *  element,
COS_Timemsec  blockTime 
)

Insert an element into the tail of the queue by copy.

Parameters
selfThe queue.
elementPointer to data to copy into queue.
blockTimeTime in ms to wait for space in the queue.
Returns
Error code.
size_t CCThreadedQueue_MaxSize ( struct CCThreadedQueue self)

Get the maximum number of elements allowed in the queue.

Parameters
selfThe queue.
Returns
The maximum number of elements allowed in the queue.
CCTQueueError CCThreadedQueue_Peek ( struct CCThreadedQueue self,
void *  element,
COS_Timemsec  blockTime 
)

Peek at the element in the head of the queue by copy. This does not remove the head.

Parameters
selfThe queue.
elementData in the head of the queue will be copied to the location pointed to by this.
blockTimeTime to wait in ms for data to be in the queue.
Returns
An error code.
CCTQueueError CCThreadedQueue_Remove ( struct CCThreadedQueue self,
void *  element,
COS_Timemsec  blockTime 
)

Remove an element from the head of the queue by copy.

Parameters
selfThe queue
elementData in the head of the queue will be copied into the location pointed to by this. Pass in NULL to remove the the head of the queue without copying out the data.
blockTimeTime in ms to wait for data to be in the queue.
Returns
An error code.

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