cQueue 2.0
Queue handling library (written in plain c)
Loading...
Searching...
No Matches
Macros | Functions
cQueue.c File Reference

Queue handling library (written in plain c) More...

#include <string.h>
#include <stdlib.h>
#include "cQueue.h"
Include dependency graph for cQueue.c:

Macros

#define QUEUE_INITIALIZED   0x5AA5U
 Initialized queue control value.
 

Functions

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
 

Detailed Description

Queue handling library (written in plain c)

Author
SMFSW

Queue handling library (written in plain c)

Macro Definition Documentation

◆ QUEUE_INITIALIZED

#define QUEUE_INITIALIZED   0x5AA5U

Initialized queue control value.

Function Documentation

◆ q_drop()

bool q_drop ( Queue_t *const pQ)

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
trueif successfully dropped from queue
falseif queue is empty

◆ q_flush()

void q_flush ( Queue_t *const pQ)

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
Here is the call graph for this function:

◆ 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)
Here is the call graph for this function:

◆ 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
trueif queue is empty
falseis 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
trueif queue is full
falseis 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
trueif queue is allocated
falseis queue is not allocated

◆ q_kill()

void q_kill ( Queue_t *const pQ)

Queue destructor: release dynamically allocated queue.

Parameters
[in,out]pQ- pointer of queue to handle
Here is the caller graph for this function:

◆ 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
trueif successfully peeked from queue
falseif 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
trueif successfully peeked from queue
falseif index is out of range
Here is the caller graph for this function:

◆ 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
trueif successfully peeked from queue
falseif queue is empty
Here is the call graph for this function:

◆ 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
trueif successfully pulled from queue
falseif 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
trueif successfully pushed into queue
falseif queue is full

◆ q_sizeof()

uint32_t q_sizeof ( const Queue_t *const pQ)

get size of queue

Remarks
Size in bytes (like sizeof)
Parameters
[in]pQ- pointer of queue to handle
Returns
Size of queue in bytes