19#define CHECK_NULL_PRT(ptr) (((ptr) != NULL) ? QTIP_STATUS_OK : QTIP_STATUS_NULL_PTR)
24#define IS_LOCKED(context) ((!is_locked((context))) ? QTIP_STATUS_OK : QTIP_STATUS_LOCKED)
29#define CHECK_STATUS(status, exp) (((status) == QTIP_STATUS_OK) ? (exp) : (status))
42 return pContext->
qty == 0U;
57 memcpy(absolute_index_to_address(pContext, index), pItem, pContext->
itemSize);
62 memcpy(pItem, absolute_index_to_address(pContext, index), pContext->
itemSize);
67 memset(absolute_index_to_address(pContext, index), 0U, pContext->
itemSize);
77 return absolute_index_to_address(pContext, relative_index_to_absolute(pContext, index));
82 write_item_absolute(pContext, relative_index_to_absolute(pContext, index), pItem);
87 read_item_absolute(pContext, relative_index_to_absolute(pContext, index), pItem);
92 delete_item_absolute(pContext, relative_index_to_absolute(pContext, index));
102 return (index + 1U) % pContext->
maxItems;
107 return next_index_absolute(pContext, relative_index_to_absolute(pContext, index));
132 if (is_empty(pContext))
138 newHeadIndex = next_index_absolute(pContext, index);
146 void* pHead = relative_index_to_address(pContext, index);
149 for (i = index; i < pContext->
qty - 2U; i++)
151 const void* pNextItem = relative_index_to_address(pContext, i + 1U);
152 memcpy(pHead, pNextItem, pContext->
itemSize);
153 pHead = (
void*) pNextItem;
156 delete_item_relative(pContext, i + 1U);
167#ifndef SKIP_ARG_CHECK
182 pContext->
start = pBuffer;
183 pContext->
front = 0U;
189#ifndef DISABLE_TELEMETRY
190 pContext->
total = 0U;
202#ifndef SKIP_ARG_CHECK
213 if (!is_full(pContext))
216 lock_queue(pContext);
218 pContext->
rear = move_index(pContext, pContext->
rear);
220 write_item_absolute(pContext, pContext->
rear, pItem);
223#ifndef DISABLE_TELEMETRY
228 unlock_queue(pContext);
244#ifndef SKIP_ARG_CHECK
255 if (!is_empty(pContext))
258 lock_queue(pContext);
260 read_item_absolute(pContext, pContext->
front, pItem);
261 delete_item_absolute(pContext, pContext->
front);
264 pContext->
front = move_index(pContext, pContext->
front);
266#ifndef DISABLE_TELEMETRY
271 unlock_queue(pContext);
287#ifndef SKIP_ARG_CHECK
300 lock_queue(pContext);
302 *pSize = count_items(pContext);
305 read_item_relative(pContext, i, pBuffer + i * pContext->
itemSize);
309 unlock_queue(pContext);
320#ifndef SKIP_ARG_CHECK
331 lock_queue(pContext);
334 reset_queue(pContext);
336 pContext->
front = move_index(pContext, pContext->
front);
337 pContext->
rear = move_index(pContext, pContext->
rear);
340 unlock_queue(pContext);
351#ifndef SKIP_ARG_CHECK
362 if (!is_empty(pContext))
365 lock_queue(pContext);
368 read_item_absolute(pContext, pContext->
rear, pItem);
371 unlock_queue(pContext);
387#ifndef SKIP_ARG_CHECK
398 if (!is_empty(pContext))
401 lock_queue(pContext);
404 read_item_absolute(pContext, pContext->
front, pItem);
407 unlock_queue(pContext);
425#ifndef SKIP_ARG_CHECK
441#ifndef SKIP_ARG_CHECK
447 lock_queue(pContext);
457#ifndef SKIP_ARG_CHECK
463 unlock_queue(pContext);
476#ifndef SKIP_ARG_CHECK
492#ifndef SKIP_ARG_CHECK
508#ifndef SKIP_ARG_CHECK
514 *pResult = count_items(pContext);
524#ifndef SKIP_ARG_CHECK
537 read_item_relative(pContext, index, pItem);
547#ifndef SKIP_ARG_CHECK
559 delete_item_relative(pContext, index);
560 sweep_items(pContext, index);
571#ifndef SKIP_ARG_CHECK
584 read_item_relative(pContext, index, pItem);
585 delete_item_relative(pContext, index);
586 sweep_items(pContext, index);
595#ifndef DISABLE_TELEMETRY
601#ifndef SKIP_ARG_CHECK
608 *pResult = pContext->
total;
618#ifndef SKIP_ARG_CHECK
qtipSize_t rear
Absolute index of the rear of the queue.
qtipSize_t maxItems
Number of items allowed in the queue.
size_t total
Number of items introduced to the queue.
qtipSize_t qty
Current number of items in the queue.
void * start
Pointer to the start of the queue.
size_t itemSize
Size of each item in the queue.
size_t processed
Number of items removed from the queue.
qtipSize_t front
Absolute index of the front of the queue.
qtipStatus_t qtip_put(qtipContext_t *pContext, void *pItem)
Put an item in a queue.
qtipStatus_t qtip_count_items(qtipContext_t *pContext, qtipSize_t *pResult)
Gets the number of items in the queue.
qtipStatus_t qtip_is_full(qtipContext_t *pContext)
Checks whether the queue is full.
size_t qtipSize_t
Number of items in queue.
qtipStatus_t qtip_get_front(qtipContext_t *pContext, void *pItem)
Gets the item at the front of the queue.
qtipStatus_t
Queue operation status.
qtipStatus_t qtip_unlock(qtipContext_t *pContext)
Unlocks the queue.
qtipStatus_t qtip_total_processed_items(qtipContext_t *pContext, size_t *pResult)
Get number of processed items in the queue.
qtipStatus_t qtip_get_rear(qtipContext_t *pContext, void *pItem)
Gets the item at the rear of the queue.
qtipStatus_t qtip_pop(qtipContext_t *pContext, void *pItem)
Extract the next item from the queue.
qtipStatus_t qtip_peek(qtipContext_t *pContext, void *pBuffer, qtipSize_t *pSize)
Copies every element of the queue into a buffer.
qtipStatus_t qtip_is_empty(qtipContext_t *pContext)
Checks whether the queue is empty.
qtipStatus_t qtip_is_locked(qtipContext_t *pContext)
Checks whether the queue is locked.
qtipStatus_t qtip_remove_item_index(qtipContext_t *pContext, qtipSize_t index)
Removes the item from an intex in the queue.
qtipStatus_t qtip_purge(qtipContext_t *pContext)
Removes all the items from the queue.
qtipStatus_t qtip_total_enqueued_items(qtipContext_t *pContext, size_t *pResult)
Get number of items inserted in the queue.
qtipStatus_t qtip_init(qtipContext_t *pContext, void *pBuffer, qtipSize_t maxItems, size_t itemSize)
Initialize queue context.
qtipStatus_t qtip_get_item_index(qtipContext_t *pContext, qtipSize_t index, void *pItem)
Gets the item from an intex in the queue.
qtipStatus_t qtip_get_pop_index(qtipContext_t *pContext, qtipSize_t index, void *pItem)
Pops the item from an intex in the queue.
qtipStatus_t qtip_lock(qtipContext_t *pContext)
Locks the queue.
@ QTIP_STATUS_EMPTY
Queue is empty.
@ QTIP_STATUS_INVALID_SIZE
Invalid queue size.
@ QTIP_STATUS_OK
Operation succeded.
@ QTIP_STATUS_FULL
Queue is full.
#define CHECK_NULL_PRT(ptr)
Check whether the input is a null pointer.
#define IS_LOCKED(context)
Check whether the queue is locked.
#define CHECK_STATUS(status, exp)
Combine the current status with a new expression.