QTip
C library for queues
Loading...
Searching...
No Matches
qtip.h
Go to the documentation of this file.
1
13#ifndef QTIP_H
14#define QTIP_H
15
16#ifdef __cplusplus
17// clang-format off
18#define QTIP_CPP_SUPPORT_START extern "C" {
19#define QTIP_CPP_SUPPORT_END }
20#define QTIP_IS_CPP (1U)
21#else
22#define QTIP_CPP_SUPPORT_START
23#define QTIP_CPP_SUPPORT_END
24#define QTIP_IS_CPP (0U)
25// clang-format on
26#endif
27
28QTIP_CPP_SUPPORT_START
29
30#include <stdbool.h>
31#include <stddef.h>
32
33/*
34 * Public defines
35 */
36#ifndef SIZE_TYPE
37#define SIZE_TYPE size_t
38#else
39#include <stdint.h>
40#endif
41
42/*
43 * Public typedefs
44 */
46
47/*
48 * Public Enum
49 */
50
63
64/*
65 * Public Structs
66 */
67
71typedef struct
72{
75 void* start;
78 size_t itemSize;
79#ifndef DISABLE_LOCK
80 bool locked;
81#endif
82#ifndef DISABLE_TELEMETRY
83 size_t processed;
84 size_t total;
85#endif
87
88/*
89 * Public API
90 */
91
112qtipStatus_t qtip_init(qtipContext_t* pContext, void* pQueue, qtipSize_t maxItems, size_t itemSize);
113
131qtipStatus_t qtip_put(qtipContext_t* pContext, void* pItem);
132
150qtipStatus_t qtip_pop(qtipContext_t* pContext, void* pItem);
151
171qtipStatus_t qtip_peek(qtipContext_t* pContext, void* pBuffer, qtipSize_t* pSize);
172
190
208qtipStatus_t qtip_get_front(qtipContext_t* pContext, void* pItem);
209
227qtipStatus_t qtip_get_rear(qtipContext_t* pContext, void* pItem);
228
229#ifndef REDUCED_API
230
247
265
283
303qtipStatus_t qtip_get_item_index(qtipContext_t* pContext, qtipSize_t index, void* pItem);
304
324
344qtipStatus_t qtip_get_pop_index(qtipContext_t* pContext, qtipSize_t index, void* pItem);
345
346#endif // REDUCED_API
347
348#ifndef DISABLE_LOCK
349
367
384
401
402#endif // DISABLE_LOCK
403
404#ifndef DISABLE_TELEMETRY
405
423qtipStatus_t qtip_total_enqueued_items(qtipContext_t* pContext, size_t* pResult);
424
442qtipStatus_t qtip_total_processed_items(qtipContext_t* pContext, size_t* pResult);
443
444#endif // DISABLE_TELEMETRY
445
446#endif // QTIP_H
447
448QTIP_CPP_SUPPORT_END
449
bool locked
Lock status.
Definition qtip.h:80
qtipSize_t rear
Absolute index of the rear of the queue.
Definition qtip.h:77
qtipSize_t maxItems
Number of items allowed in the queue.
Definition qtip.h:73
size_t total
Number of items introduced to the queue.
Definition qtip.h:84
qtipSize_t qty
Current number of items in the queue.
Definition qtip.h:74
void * start
Pointer to the start of the queue.
Definition qtip.h:75
size_t itemSize
Size of each item in the queue.
Definition qtip.h:78
size_t processed
Number of items removed from the queue.
Definition qtip.h:83
qtipSize_t front
Absolute index of the front of the queue.
Definition qtip.h:76
qtipStatus_t qtip_put(qtipContext_t *pContext, void *pItem)
Put an item in a queue.
Definition qtip.c:198
qtipStatus_t qtip_count_items(qtipContext_t *pContext, qtipSize_t *pResult)
Gets the number of items in the queue.
Definition qtip.c:504
qtipStatus_t qtip_is_full(qtipContext_t *pContext)
Checks whether the queue is full.
Definition qtip.c:472
size_t qtipSize_t
Number of items in queue.
Definition qtip.h:45
qtipStatus_t qtip_get_front(qtipContext_t *pContext, void *pItem)
Gets the item at the front of the queue.
Definition qtip.c:383
qtipStatus_t
Queue operation status.
Definition qtip.h:55
qtipStatus_t qtip_unlock(qtipContext_t *pContext)
Unlocks the queue.
Definition qtip.c:453
qtipStatus_t qtip_total_processed_items(qtipContext_t *pContext, size_t *pResult)
Get number of processed items in the queue.
Definition qtip.c:614
qtipStatus_t qtip_get_rear(qtipContext_t *pContext, void *pItem)
Gets the item at the rear of the queue.
Definition qtip.c:347
qtipStatus_t qtip_pop(qtipContext_t *pContext, void *pItem)
Extract the next item from the queue.
Definition qtip.c:240
qtipStatus_t qtip_peek(qtipContext_t *pContext, void *pBuffer, qtipSize_t *pSize)
Copies every element of the queue into a buffer.
Definition qtip.c:283
qtipStatus_t qtip_is_empty(qtipContext_t *pContext)
Checks whether the queue is empty.
Definition qtip.c:488
#define SIZE_TYPE
Type for holding the number of items in queue.
Definition qtip.h:37
qtipStatus_t qtip_is_locked(qtipContext_t *pContext)
Checks whether the queue is locked.
Definition qtip.c:421
qtipStatus_t qtip_remove_item_index(qtipContext_t *pContext, qtipSize_t index)
Removes the item from an intex in the queue.
Definition qtip.c:543
qtipStatus_t qtip_purge(qtipContext_t *pContext)
Removes all the items from the queue.
Definition qtip.c:316
qtipStatus_t qtip_total_enqueued_items(qtipContext_t *pContext, size_t *pResult)
Get number of items inserted in the queue.
Definition qtip.c:597
qtipStatus_t qtip_init(qtipContext_t *pContext, void *pQueue, qtipSize_t maxItems, size_t itemSize)
Initialize queue context.
Definition qtip.c:163
qtipStatus_t qtip_get_item_index(qtipContext_t *pContext, qtipSize_t index, void *pItem)
Gets the item from an intex in the queue.
Definition qtip.c:520
qtipStatus_t qtip_get_pop_index(qtipContext_t *pContext, qtipSize_t index, void *pItem)
Pops the item from an intex in the queue.
Definition qtip.c:567
qtipStatus_t qtip_lock(qtipContext_t *pContext)
Locks the queue.
Definition qtip.c:437
@ QTIP_STATUS_EMPTY
Queue is empty.
Definition qtip.h:58
@ QTIP_STATUS_LOCKED
Queue is locked.
Definition qtip.h:61
@ QTIP_STATUS_INVALID_SIZE
Invalid queue size.
Definition qtip.h:60
@ QTIP_STATUS_NULL_PTR
Null pointer encountered.
Definition qtip.h:59
@ QTIP_STATUS_OK
Operation succeded.
Definition qtip.h:56
@ QTIP_STATUS_FULL
Queue is full.
Definition qtip.h:57
Queue context structure.
Definition qtip.h:72