23 #ifndef ETCPAL_CPP_QUEUE_H
24 #define ETCPAL_CPP_QUEUE_H
30 #include "etcpal/common.h"
31 #include "etcpal/queue.h"
95 static_assert(std::is_trivially_copyable<T>::value,
"Type T in etcpal::Queue<T> must be trivially copyable.");
98 explicit Queue(
size_t size);
102 Queue& operator=(
const Queue& other) =
delete;
110 template <
class Rep,
class Period>
111 bool Receive(T& data,
const std::chrono::duration<Rep, Period>& timeout);
182 template <
class Rep,
class Period>
185 int timeout_ms_clamped =
186 static_cast<int>(std::min(std::chrono::milliseconds(timeout).count(),
187 static_cast<std::chrono::milliseconds::rep
>(std::numeric_limits<int>::max())));
An RTOS queue class.
Definition: queue.h:94
~Queue()
Destroy a queue.
Definition: queue.h:137
bool SendFromIsr(const T &data)
Add to a queue from an interrupt service routine.
Definition: queue.h:160
bool Reset()
Resets queue to empty state.
Definition: queue.h:204
bool ReceiveFromIsr(T &data)
Get an item from the queue from an interrupt context.
Definition: queue.h:195
bool IsEmpty() const
Check if a queue is empty.
Definition: queue.h:213
bool IsEmptyFromIsr() const
Check if a queue is empty from an interrupt service routine.
Definition: queue.h:222
bool IsFullFromIsr() const
Check if a queue is full from an interrupt service routine.
Definition: queue.h:240
bool Send(const T &data, int timeout_ms=ETCPAL_WAIT_FOREVER)
Add some data to the queue.
Definition: queue.h:151
bool Receive(T &data, int timeout_ms=ETCPAL_WAIT_FOREVER)
Get an item from the queue.
Definition: queue.h:170
Queue(size_t size)
Create a new queue.
Definition: queue.h:130
size_t SlotsUsedFromIsr() const
Get number of slots being stored in the queue from an interrupt service routine.
Definition: queue.h:258
size_t SlotsUsed() const
Get number of slots being stored in the queue.
Definition: queue.h:249
size_t SlotsAvailable() const
Get number of remaining slots in the queue.
Definition: queue.h:267
bool IsFull() const
Check if a queue is full.
Definition: queue.h:231
Common definitions used by EtcPal C++ wrappers.
bool etcpal_queue_is_empty_from_isr(const etcpal_queue_t *id)
Determine whether a queue is currently empty from an interrupt context.
Definition: queue.c:375
size_t etcpal_queue_slots_available(const etcpal_queue_t *id)
Get number of remaining slots in the queue.
Definition: queue.c:441
bool etcpal_queue_timed_receive(etcpal_queue_t *id, void *data, int timeout_ms)
Retrieve the first item from a queue, giving up after a timeout.
Definition: queue.c:309
bool etcpal_queue_send_from_isr(etcpal_queue_t *id, const void *data)
Add an item to a queue from an interrupt context.
Definition: queue.c:321
bool etcpal_queue_is_full_from_isr(const etcpal_queue_t *id)
Determine whether a queue is currently full from an interrupt context.
Definition: queue.c:401
bool etcpal_queue_is_empty(const etcpal_queue_t *id)
Determine whether a queue is currently empty.
Definition: queue.c:363
PLATFORM_DEFINED etcpal_queue_t
The queue identifier.
Definition: queue.dox:85
bool etcpal_queue_is_full(const etcpal_queue_t *id)
Determine whether a queue is currently full.
Definition: queue.c:389
bool etcpal_queue_reset(const etcpal_queue_t *id)
Resets queue to empty state.
bool etcpal_queue_receive_from_isr(etcpal_queue_t *id, void *data)
Retrieve the first item from a queue from an interrupt context.
Definition: queue.c:333
void etcpal_queue_destroy(etcpal_queue_t *id)
Destroy a queue.
Definition: queue.c:241
size_t etcpal_queue_slots_used(const etcpal_queue_t *id)
Get number of slots being stored in the queue.
Definition: queue.c:415
size_t etcpal_queue_slots_used_from_isr(const etcpal_queue_t *id)
Get number of slots being stored in the queue from an interrupt context.
Definition: queue.c:428
bool etcpal_queue_timed_send(etcpal_queue_t *id, const void *data, int timeout_ms)
Add an item to a queue, giving up after a timeout.
Definition: queue.c:285
bool etcpal_queue_create(etcpal_queue_t *id, size_t size, size_t item_size)
Create a new queue.
Definition: queue.c:194
#define ETCPAL_WAIT_FOREVER
For etcpal_ functions that take a millisecond timeout, this means to wait indefinitely.
Definition: common.h:118