An interface to a FIFO queue with thread blocking calls.
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] | elementSize | size (in bytes) of a single element stored in queue |
[in] | capacity | maximum 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
-
bool OSQUEUE_IsValid |
( |
OSQueue |
queue | ) |
|
Checks if a given queue handle represents a valid queue.
- Parameters
-
- 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] | queue | queue handle |
[in] | element | pointer to a data to be stored as an element of the queue |
[in] | timeout | maximum 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] | queue | queue handle |
[in] | placeToStore | pointer to place where element data will be stored |
[in] | timeout | maximum 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
-
- 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
-
- Returns
- number of elements currently in queue