CardSight 0.1.0
C API reference for the CardSight firmware and application
Loading...
Searching...
No Matches
message_queue.h File Reference

Message queues: fixed-size items between tasks. More...

#include <errno.h>

Go to the source code of this file.

Data Structures

struct  message_queue
 A queue of equal-sized items between tasks. More...

Functions

int msg_queue_init (struct message_queue *queue, uint32_t item_size, uint32_t capacity)
 Create a message queue.
int msg_queue_put (struct message_queue *queue, const void *item, int timeout_ms)
 Copy an item into a queue.
int msg_queue_get (struct message_queue *queue, void *item, int timeout_ms)
 Copy the oldest item out of a queue.

Detailed Description

Message queues: fixed-size items between tasks.

A negative timeout waits forever, 0 does not wait; get and put answer 0 or -ETIMEDOUT / -ENOMEM.

Function Documentation

◆ msg_queue_get()

int msg_queue_get ( struct message_queue * queue,
void * item,
int timeout_ms )

Copy the oldest item out of a queue.

Parameters
[in]queueInitialized queue.
[out]itemDestination for the item; item_size bytes are written.
[in]timeout_msMilliseconds to wait for an item; negative waits forever, 0 does not wait.
Returns
0 when an item was copied, -ETIMEDOUT when none arrived in time, or -EINVAL for a bad queue.

◆ msg_queue_init()

int msg_queue_init ( struct message_queue * queue,
uint32_t item_size,
uint32_t capacity )

Create a message queue.

Parameters
[out]queueQueue structure to initialize.
[in]item_sizeSize of one item in bytes; must be non-zero.
[in]capacityNumber of items the queue holds; must be non-zero.
Returns
0 on success, -EINVAL for a bad argument, or -ENOMEM without queue memory.

◆ msg_queue_put()

int msg_queue_put ( struct message_queue * queue,
const void * item,
int timeout_ms )

Copy an item into a queue.

Parameters
[in]queueInitialized queue.
[in]itemItem to copy; item_size bytes are read.
[in]timeout_msMilliseconds to wait for room; negative waits forever, 0 does not wait.
Returns
0 when queued, -ETIMEDOUT when no room arrived in time, or -EINVAL for a bad queue.