Queue handling library (written in plain c)
More...
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
struct | Queue_t |
| Queue type structure holding all variables to handle the queue. More...
|
|
|
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)
|
|
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)
|
|
void | q_kill (Queue_t *const pQ) |
| Queue destructor: release dynamically allocated queue.
|
|
void | q_flush (Queue_t *const pQ) |
| Flush queue, restarting from empty queue.
|
|
bool | q_push (Queue_t *const pQ, const void *const record) |
| Push record to queue.
|
|
bool | q_pop (Queue_t *const pQ, void *const record) |
| Pop record from queue.
|
|
bool | q_peek (const Queue_t *const pQ, void *const record) |
| Peek record from queue.
|
|
bool | q_drop (Queue_t *const pQ) |
| Drop current record from queue.
|
|
bool | q_peekIdx (const Queue_t *const pQ, void *const record, const uint16_t idx) |
| Peek record at index from queue.
|
|
bool | q_peekPrevious (const Queue_t *const pQ, void *const record) |
| Peek previous record from queue.
|
|
bool | q_isInitialized (const Queue_t *const pQ) |
| get initialization state of the queue
|
|
uint32_t | q_sizeof (const Queue_t *const pQ) |
| get size of queue
|
|
bool | q_isEmpty (const Queue_t *const pQ) |
| get emptiness state of the queue
|
|
bool | q_isFull (const Queue_t *const pQ) |
| get fullness state of the queue
|
|
uint16_t | q_getCount (const Queue_t *const pQ) |
| get number of records in the queue
|
|
uint16_t | q_getRemainingCount (const Queue_t *const pQ) |
| get number of records left in the queue
|
|
Queue handling library (written in plain c)
- Author
- SMFSW
- Copyright
- BSD 3-Clause License (c) 2017-2024, SMFSW
Queue handling library (written in plain c)
◆ q_clean
- Deprecated
- q_clean was already used in cQueue lib, alias is made to keep compatibility with earlier versions
◆ q_init_def
#define q_init_def |
( |
| q, |
|
|
| sz ) q_init(q, sz, 20, FIFO, false) |
Some kind of default behavior for queue initialization.
◆ q_nbRecs
- Deprecated
- q_nbRecs was already used in cQueue lib, alias is made to keep compatibility with earlier versions
◆ q_pull
- Deprecated
- q_pull was already used in cQueue lib, alias is made to keep compatibility with earlier versions
◆ Queue_t
typedef struct Queue_t Queue_t |
◆ QueueType
◆ enumQueueType
Queue behavior enumeration (FIFO, LIFO)
Enumerator |
---|
FIFO | First In First Out behavior.
|
LIFO | Last In First Out behavior.
|
◆ q_drop()
Drop current record from queue.
- Warning
- If using q_push, q_pop, q_peek, q_drop, q_peekItem and/or q_peekPrevious in both interrupts and main application, you shall disable interrupts in main application when using these functions
- Note
- This function is most likely to be used in conjunction with q_peek
- Parameters
-
[in,out] | pQ | - pointer of queue to handle |
- Returns
- drop status
- Return values
-
true | if successfully dropped from queue |
false | if queue is empty |
◆ q_flush()
Flush queue, restarting from empty queue.
- Parameters
-
[in,out] | pQ | - pointer of queue to handle |
◆ q_getCount()
uint16_t q_getCount |
( |
const Queue_t *const | pQ | ) |
|
get number of records in the queue
- Parameters
-
[in] | pQ | - pointer of queue to handle |
- Returns
- Number of records stored in the queue
◆ q_getRemainingCount()
uint16_t q_getRemainingCount |
( |
const Queue_t *const | pQ | ) |
|
get number of records left in the queue
- Parameters
-
[in] | pQ | - pointer of queue to handle |
- Returns
- Number of records left in the queue
◆ q_init()
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)
- Parameters
-
[in,out] | pQ | - pointer of queue to handle |
[in] | size_rec | - size of a record in the queue (in bytes) |
[in] | nb_recs | - number of records in the queue |
[in] | type | - Queue implementation type: FIFO, LIFO |
[in] | overwrite | - Overwrite previous records when queue is full |
- Returns
- NULL when allocation not possible, Queue tab address when successful
◆ q_init_static()
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)
- Parameters
-
[in,out] | pQ | - pointer of queue to handle |
[in] | size_rec | - size of a record in the queue (in bytes) |
[in] | nb_recs | - number of records in the queue |
[in] | type | - Queue implementation type: FIFO, LIFO |
[in] | overwrite | - Overwrite previous records when queue is full |
[in] | pQDat | - Pointer to static data queue |
[in] | lenQDat | - Length of static data queue (in bytes) for static array size check against required size for queue |
- Returns
- Queue tab address (to remain consistent with q_init)
◆ q_isEmpty()
bool q_isEmpty |
( |
const Queue_t *const | pQ | ) |
|
get emptiness state of the queue
- Parameters
-
[in] | pQ | - pointer of queue to handle |
- Returns
- Queue emptiness status
- Return values
-
true | if queue is empty |
false | is not empty |
◆ q_isFull()
bool q_isFull |
( |
const Queue_t *const | pQ | ) |
|
get fullness state of the queue
- Parameters
-
[in] | pQ | - pointer of queue to handle |
- Returns
- Queue fullness status
- Return values
-
true | if queue is full |
false | is not full |
◆ q_isInitialized()
bool q_isInitialized |
( |
const Queue_t *const | pQ | ) |
|
get initialization state of the queue
- Parameters
-
[in] | pQ | - pointer of queue to handle |
- Returns
- Queue initialization status
- Return values
-
true | if queue is allocated |
false | is queue is not allocated |
◆ q_kill()
Queue destructor: release dynamically allocated queue.
- Parameters
-
[in,out] | pQ | - pointer of queue to handle |
◆ q_peek()
bool q_peek |
( |
const Queue_t *const | pQ, |
|
|
void *const | record ) |
Peek record from queue.
- Warning
- If using q_push, q_pop, q_peek, q_drop, q_peekItem and/or q_peekPrevious in both interrupts and main application, you shall disable interrupts in main application when using these functions
- Note
- This function is most likely to be used in conjunction with q_drop
- Parameters
-
[in] | pQ | - pointer of queue to handle |
[in,out] | record | - pointer to record to be peeked from queue |
- Returns
- Peek status
- Return values
-
true | if successfully peeked from queue |
false | if queue is empty |
◆ q_peekIdx()
bool q_peekIdx |
( |
const Queue_t *const | pQ, |
|
|
void *const | record, |
|
|
const uint16_t | idx ) |
Peek record at index from queue.
- Warning
- If using q_push, q_pop, q_peek, q_drop, q_peekItem and/or q_peekPrevious in both interrupts and main application, you shall disable interrupts in main application when using these functions
- Note
- This function is only useful if searching for a duplicate record and shouldn't be used in conjunction with q_drop
- Parameters
-
[in] | pQ | - pointer of queue to handle |
[in,out] | record | - pointer to record to be peeked from queue |
[in] | idx | - index of the record to pick |
- Returns
- Peek status
- Return values
-
true | if successfully peeked from queue |
false | if index is out of range |
◆ q_peekPrevious()
bool q_peekPrevious |
( |
const Queue_t *const | pQ, |
|
|
void *const | record ) |
Peek previous record from queue.
- Warning
- If using q_push, q_pop, q_peek, q_drop, q_peekItem and/or q_peekPrevious in both interrupts and main application, you shall disable interrupts in main application when using these functions
- Note
- This inline is only useful with FIFO implementation, use q_peek instead with a LIFO (will lead to the same result)
- Parameters
-
[in] | pQ | - pointer of queue to handle |
[in,out] | record | - pointer to record to be peeked from queue |
- Returns
- Peek status
- Return values
-
true | if successfully peeked from queue |
false | if queue is empty |
◆ q_pop()
bool q_pop |
( |
Queue_t *const | pQ, |
|
|
void *const | record ) |
Pop record from queue.
- Warning
- If using q_push, q_pop, q_peek, q_drop, q_peekItem and/or q_peekPrevious in both interrupts and main application, you shall disable interrupts in main application when using these functions
- Parameters
-
[in] | pQ | - pointer of queue to handle |
[in,out] | record | - pointer to record to be popped from queue |
- Returns
- Pop status
- Return values
-
true | if successfully pulled from queue |
false | if queue is empty |
◆ q_push()
bool q_push |
( |
Queue_t *const | pQ, |
|
|
const void *const | record ) |
Push record to queue.
- Warning
- If using q_push, q_pop, q_peek, q_drop, q_peekItem and/or q_peekPrevious in both interrupts and main application, you shall disable interrupts in main application when using these functions
- Parameters
-
[in,out] | pQ | - pointer of queue to handle |
[in] | record | - pointer to record to be pushed into queue |
- Returns
- Push status
- Return values
-
true | if successfully pushed into queue |
false | if queue is full |
◆ q_sizeof()
uint32_t q_sizeof |
( |
const Queue_t *const | pQ | ) |
|
get size of queue
- Parameters
-
[in] | pQ | - pointer of queue to handle |
- Returns
- Size of queue in bytes