HALFRED  0.4.0
Functions
OSQueue interface

Detailed Description

An interface to a FIFO queue with thread blocking calls.

Functions

OSQueue OSQUEUE_Create (size_t elementSize, size_t capacity)
 
void OSQUEUE_Destroy (OSQueue queue)
 
bool OSQUEUE_IsValid (OSQueue queue)
 
int OSQUEUE_Put (OSQueue queue, const void *element, OSTime timeout)
 
int OSQUEUE_Get (OSQueue queue, void *placeToStore, OSTime timeout)
 
size_t OSQUEUE_GetCapacity (OSQueue queue)
 
size_t OSQUEUE_GetNumberOfElements (OSQueue queue)
 

Function Documentation

OSQueue OSQUEUE_Create ( size_t  elementSize,
size_t  capacity 
)

Creates a new queue. The memory for the queue is allocated dynamically using HEAP module. The space for queue items is pre-allocated, thus queue capacity and element size must be provided.

Parameters
[in]elementSizesize (in bytes) of a single element stored in queue
[in]capacitymaximum number of elements the queue can store
Returns
new queue handle or NULL, if the queue could not be created
void OSQUEUE_Destroy ( OSQueue  queue)

Destroys a queue previously created through a call to OSQUEUE_Create. Frees up all memory associated with the queue

Parameters
[in]queuequeue handle
bool OSQUEUE_IsValid ( OSQueue  queue)

Checks if a given queue handle represents a valid queue.

Parameters
[in]queuequeue handle
Returns
true if the queue is valid, false otherwise
int OSQUEUE_Put ( OSQueue  queue,
const void *  element,
OSTime  timeout 
)

Puts an item into the queue. The data pointed by the element argument is copied as a last element into the queue. In case there is no more space in the queue to store this element, this function blocks the calling thread, until space in the queue becomes available or timeout occurs.

Parameters
[in]queuequeue handle
[in]elementpointer to a data to be stored as an element of the queue
[in]timeoutmaximum time allowed to wait for the space in queue, in case it is not readily available
Returns
0 if the element was added to the queue or !0 if timeout or other error occurred
int OSQUEUE_Get ( OSQueue  queue,
void *  placeToStore,
OSTime  timeout 
)

Gets an element from the queue and stores it under the given pointer. The element is removed from the queue. In case no element is available in the queue, this function blocks the calling thread, until an element becomes available or timeout occurs.

Parameters
[in]queuequeue handle
[in]placeToStorepointer to place where element data will be stored
[in]timeoutmaximum time allowed to wait for the element in queue, in case it is not readily available
Returns
0 if the element was retrieved successfully or !0 if timeout or other error occurred
size_t OSQUEUE_GetCapacity ( OSQueue  queue)

Gets the maximum storage capacity of the queue.

Parameters
[in]queuequeue handle
Returns
maximum number of elements the queue can store
size_t OSQUEUE_GetNumberOfElements ( OSQueue  queue)

Gets the number of elements currently stored in the queue.

Parameters
[in]queuequeue handle
Returns
number of elements currently in queue