oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
queue.h
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
28#ifndef OVE_QUEUE_H
29#define OVE_QUEUE_H
30
31#include "ove/types.h"
32#include "ove_config.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
39typedef struct ove_queue *ove_queue_t;
40
41#include "ove/storage.h"
42
43#ifdef CONFIG_OVE_QUEUE
44
66int ove_queue_init(ove_queue_t *q, ove_queue_storage_t *storage,
67 void *buffer, size_t item_size, unsigned int max_items);
68
81
82/* _create / _destroy — heap-gated */
83#ifdef OVE_HEAP_QUEUE
84
102int ove_queue_create(ove_queue_t *q, size_t item_size,
103 unsigned int max_items);
104
115
116#elif !defined(__ZIG_CIMPORT__) /* !OVE_HEAP_QUEUE — zero-heap mode */
117
118/* Unified macro — item_size and max_items must be compile-time constants. */
119#define ove_queue_create(pq, item_size, max_items) \
120 ({ static ove_queue_storage_t _ove_stor_; \
121 static uint8_t _ove_buf_[(item_size) * (max_items)]; \
122 ove_queue_init((pq), &_ove_stor_, _ove_buf_, \
123 (item_size), (max_items)); })
124#define ove_queue_destroy(q) ove_queue_deinit(q)
125
126#endif /* OVE_HEAP_QUEUE */
127
148int ove_queue_send(ove_queue_t q, const void *data,
149 uint32_t timeout_ms);
150
174 uint32_t timeout_ms);
175
191int ove_queue_send_from_isr(ove_queue_t q, const void *data);
192
210
211#else /* !CONFIG_OVE_QUEUE */
212
213static inline int ove_queue_create(ove_queue_t *q, size_t is, unsigned int mi) { (void)q; (void)is; (void)mi; return OVE_ERR_NOT_SUPPORTED; }
214static inline void ove_queue_destroy(ove_queue_t q) { (void)q; }
215static inline int ove_queue_send(ove_queue_t q, const void *d, uint32_t t) { (void)q; (void)d; (void)t; return OVE_ERR_NOT_SUPPORTED; }
216static inline int ove_queue_receive(ove_queue_t q, void *b, uint32_t t) { (void)q; (void)b; (void)t; return OVE_ERR_NOT_SUPPORTED; }
217static inline int ove_queue_send_from_isr(ove_queue_t q, const void *d) { (void)q; (void)d; return OVE_ERR_NOT_SUPPORTED; }
218static inline int ove_queue_receive_from_isr(ove_queue_t q, void *b) { (void)q; (void)b; return OVE_ERR_NOT_SUPPORTED; }
219
220#endif /* CONFIG_OVE_QUEUE */
221
222#ifdef __cplusplus
223}
224#endif
225
226#endif /* OVE_QUEUE_H */
227
void ove_queue_destroy(ove_queue_t q)
Destroy and free a queue allocated with ove_queue_create().
int ove_queue_send(ove_queue_t q, const void *data, uint32_t timeout_ms)
Send an item to the back of the queue, blocking if it is full.
void ove_queue_deinit(ove_queue_t q)
Release resources held by a queue initialised with ove_queue_init().
int ove_queue_receive_from_isr(ove_queue_t q, void *buf)
Receive an item from the queue from an interrupt service routine.
struct ove_queue * ove_queue_t
Opaque handle for a message queue object.
Definition queue.h:39
int ove_queue_init(ove_queue_t *q, ove_queue_storage_t *storage, void *buffer, size_t item_size, unsigned int max_items)
Initialise a queue using caller-supplied static storage and data buffer.
int ove_queue_send_from_isr(ove_queue_t q, const void *data)
Send an item to the queue from an interrupt service routine.
int ove_queue_create(ove_queue_t *q, size_t item_size, unsigned int max_items)
Allocate and initialise a queue from the heap.
int ove_queue_receive(ove_queue_t q, void *buf, uint32_t timeout_ms)
Receive (remove) an item from the front of the queue, blocking if it is empty.
#define OVE_ERR_NOT_SUPPORTED
The requested feature is not supported by the active backend.
Definition types.h:38