SELKIELogger  1.0.0
Collaboration diagram for Message queues:

Classes

struct  msgqueue
 Represent a simple FIFO message queue. More...
 
struct  queueitem
 

Typedefs

typedef struct queueitem queueitem
 Each queue item is a message and pointer to the next queue entry, if any.
 
typedef struct msgqueue msgqueue
 Represent a simple FIFO message queue. More...
 

Functions

bool queue_init (msgqueue *queue)
 Ensure queue structure is set to known good values and marked valid. More...
 
void queue_destroy (msgqueue *queue)
 Invalidate queue and destroy all contents. More...
 
bool queue_push (msgqueue *queue, msg_t *item)
 Add a message to the tail of the queue. More...
 
bool queue_push_qi (msgqueue *queue, queueitem *item)
 Add a queue item to the tail of the queue. More...
 
msg_tqueue_pop (msgqueue *queue)
 Remove topmost item from the queue and return it, if queue is not empty. More...
 
int queue_count (const msgqueue *queue)
 Iterate over queue and return current number of items. More...
 

Detailed Description

Typedef Documentation

◆ msgqueue

typedef struct msgqueue msgqueue

Represent a simple FIFO message queue.

Represents a queue of items starting at msgqueue.head, with the last item at or near msgqueue.tail.

The queue is protected by the mutex at msgqueue.lock, and will only have items added and removed while msgqueue.valid remains true.

Function Documentation

◆ queue_count()

int queue_count ( const msgqueue queue)

Iterate over queue and return current number of items.

Parameters
[in]queuePointer to queue
Returns
Number of items in queue, or -1 on error

Definition at line 219 of file queue.c.

◆ queue_destroy()

void queue_destroy ( msgqueue queue)

Invalidate queue and destroy all contents.

The queue is immediately marked as invalid, and this is not undone if an error occurs.

Any remaining items are removed from the queue and destroyed.

Parameters
[in]queuePointer to queue structure to be destroyed

Definition at line 64 of file queue.c.

◆ queue_init()

bool queue_init ( msgqueue queue)

Ensure queue structure is set to known good values and marked valid.

Will not re-initialise a queue if it is still valid or has a head or tail value set. Other threads might be able to add entries to the queue between the queue being marked valid and this function returning to the caller.

Parameters
[in]queuePointer to queue structure to be initialised
Returns
True on success, false otherwise

Definition at line 35 of file queue.c.

◆ queue_pop()

msg_t* queue_pop ( msgqueue queue)

Remove topmost item from the queue and return it, if queue is not empty.

Atomically remove the first entry in the queue and return it. The underlying queue item is freed, but our caller must destroy and free the message itself.

The queue item is freed, but the caller is responsible for destroying and freeing the message itself after use (i.e. the caller now owns the message, not the queue or the sending function).

Parameters
[in]queuePointer to queue
Returns
Pointer to previously queued message

Definition at line 186 of file queue.c.

◆ queue_push()

bool queue_push ( msgqueue queue,
msg_t msg 
)

Add a message to the tail of the queue.

Messages are wrapped into a queue item structure, and passed immediately to queue_push_qi()

Parameters
[in]queuePointer to queue
[in]msgPointer to message
Returns
Return value of queue_push_qi()

Definition at line 103 of file queue.c.

◆ queue_push_qi()

bool queue_push_qi ( msgqueue queue,
queueitem item 
)

Add a queue item to the tail of the queue.

Will not append to an invalid queue.

Once pushed to the queue, the queue owns the message embedded in item and the caller should not destroy or free it. That will be handled in queue_destroy() or the function responsible for consuming items out of the queue.

Parameters
[in]queuePointer to queue
[in]itemPointer to a queue item
Returns
True if item successfully appended to queue, false otherwise

Definition at line 128 of file queue.c.