cQueue 2.0
Queue handling library (written in plain c)
Loading...
Searching...
No Matches
cQueue.h
Go to the documentation of this file.
1
7/****************************************************************/
8#ifndef CQUEUE_H_
9 #define CQUEUE_H_
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15#include <inttypes.h>
16#include <stdbool.h>
17#include <stddef.h>
18/****************************************************************/
19
20
21#define q_init_def(q, sz) q_init(q, sz, 20, FIFO, false)
22
23#define q_pull q_pop
24#define q_nbRecs q_getCount
25#define q_clean q_flush
26
27
31typedef enum enumQueueType {
32 FIFO = 0,
33 LIFO = 1
35
36
40typedef struct Queue_t {
42 bool ovw;
43 bool dynamic;
44 size_t queue_sz;
45 size_t rec_sz;
46 uint16_t rec_nb;
47 uint8_t * queue;
48
49 uint16_t in;
50 uint16_t out;
51 uint16_t cnt;
52 uint16_t init;
54
55
56/*****************/
57/*** FUNCTIONS ***/
58/*****************/
67void * __attribute__((nonnull)) q_init( Queue_t * const pQ,
68 const size_t size_rec, const uint16_t nb_recs,
69 const QueueType type, const bool overwrite);
70
81void * __attribute__((nonnull(1))) q_init_static( Queue_t * const pQ,
82 const size_t size_rec, const uint16_t nb_recs,
83 const QueueType type, const bool overwrite,
84 void * const pQDat, const size_t lenQDat);
85
89void __attribute__((nonnull)) q_kill(Queue_t * const pQ);
90
94void __attribute__((nonnull)) q_flush(Queue_t * const pQ);
95
105bool __attribute__((nonnull)) q_push(Queue_t * const pQ, const void * const record);
106
116bool __attribute__((nonnull)) q_pop(Queue_t * const pQ, void * const record);
117
128bool __attribute__((nonnull)) q_peek(const Queue_t * const pQ, void * const record);
129
139bool __attribute__((nonnull)) q_drop(Queue_t * const pQ);
140
152bool __attribute__((nonnull)) q_peekIdx(const Queue_t * const pQ, void * const record, const uint16_t idx);
153
164bool __attribute__((nonnull)) q_peekPrevious(const Queue_t * const pQ, void * const record);
165
166
167/***************/
168/*** GETTERS ***/
169/***************/
176bool __attribute__((nonnull)) q_isInitialized(const Queue_t * const pQ);
177
183uint32_t __attribute__((nonnull)) q_sizeof(const Queue_t * const pQ);
184
191bool __attribute__((nonnull)) q_isEmpty(const Queue_t * const pQ);
192
199bool __attribute__((nonnull)) q_isFull(const Queue_t * const pQ);
200
205uint16_t __attribute__((nonnull)) q_getCount(const Queue_t * const pQ);
206
211uint16_t __attribute__((nonnull)) q_getRemainingCount(const Queue_t * const pQ);
212
213
214/****************************************************************/
215#ifdef __cplusplus
216}
217#endif
218
219#endif /* CQUEUE_H_ */
220/****************************************************************/
uint32_t q_sizeof(const Queue_t *const pQ)
get size of queue
Definition cQueue.c:309
enum enumQueueType QueueType
bool q_push(Queue_t *const pQ, const void *const record)
Push record to queue.
Definition cQueue.c:150
bool q_isInitialized(const Queue_t *const pQ)
get initialization state of the queue
Definition cQueue.c:306
void q_kill(Queue_t *const pQ)
Queue destructor: release dynamically allocated queue.
Definition cQueue.c:135
bool q_peek(const Queue_t *const pQ, void *const record)
Peek record from queue.
Definition cQueue.c:214
void * q_init(Queue_t *const pQ, const size_t size_rec, const uint16_t nb_recs, const QueueType type, const bool overwrite)
Queue initialization (using dynamic queue allocation)
Definition cQueue.c:85
bool q_isEmpty(const Queue_t *const pQ)
get emptiness state of the queue
Definition cQueue.c:312
bool q_isFull(const Queue_t *const pQ)
get fullness state of the queue
Definition cQueue.c:315
uint16_t q_getRemainingCount(const Queue_t *const pQ)
get number of records left in the queue
Definition cQueue.c:321
enumQueueType
Queue behavior enumeration (FIFO, LIFO)
Definition cQueue.h:31
@ FIFO
First In First Out behavior.
Definition cQueue.h:32
@ LIFO
Last In First Out behavior.
Definition cQueue.h:33
bool q_peekIdx(const Queue_t *const pQ, void *const record, const uint16_t idx)
Peek record at index from queue.
Definition cQueue.c:269
bool q_peekPrevious(const Queue_t *const pQ, void *const record)
Peek previous record from queue.
Definition cQueue.c:296
void q_flush(Queue_t *const pQ)
Flush queue, restarting from empty queue.
Definition cQueue.c:142
bool q_drop(Queue_t *const pQ)
Drop current record from queue.
Definition cQueue.c:244
bool q_pop(Queue_t *const pQ, void *const record)
Pop record from queue.
Definition cQueue.c:184
struct Queue_t Queue_t
uint16_t q_getCount(const Queue_t *const pQ)
get number of records in the queue
Definition cQueue.c:318
void * q_init_static(Queue_t *const pQ, const size_t size_rec, const uint16_t nb_recs, const QueueType type, const bool overwrite, void *const pQDat, const size_t lenQDat)
Queue initialization (using static queue)
Definition cQueue.c:111
Queue type structure holding all variables to handle the queue.
Definition cQueue.h:40
bool ovw
Overwrite previous records when queue is full allowed.
Definition cQueue.h:42
uint16_t cnt
number of records not retrieved from the queue
Definition cQueue.h:51
bool dynamic
Set to true when queue is dynamically allocated.
Definition cQueue.h:43
uint16_t out
number of records pulled from the queue (only for FIFO)
Definition cQueue.h:50
QueueType impl
Queue implementation: FIFO LIFO.
Definition cQueue.h:41
size_t rec_sz
Size of a record.
Definition cQueue.h:45
uint16_t rec_nb
number of records in the queue
Definition cQueue.h:46
uint16_t init
set to QUEUE_INITIALIZED after successful init of the queue and reset when killing queue
Definition cQueue.h:52
uint16_t in
number of records pushed into the queue
Definition cQueue.h:49
uint8_t * queue
Queue start pointer (when allocated)
Definition cQueue.h:47
size_t queue_sz
Size of the full queue.
Definition cQueue.h:44