23 #ifndef ETCPAL_CPP_STATIC_QUEUE_H
24 #define ETCPAL_CPP_STATIC_QUEUE_H
26 #include "etcpal/common.h"
28 #include "etcpal/queue.h"
96 template <
class T,
unsigned N>
99 static_assert(std::is_trivially_copyable<T>::value,
"Type T in etcpal::StaticQueue<T> must be trivially copyable.");
100 static_assert(N > 0,
"The number of elements in a static queue must be greater than 0");
117 template <
class Rep,
class Period>
118 bool Receive(T& data,
const std::chrono::duration<Rep, Period>& timeout);
131 uint8_t buffer[N *
sizeof(T)];
134 template <
class T,
unsigned N>
137 bool true_if_success =
false;
139 assert(true_if_success);
143 template <
class T,
unsigned N>
158 template <
class T,
unsigned N>
167 template <
class T,
unsigned N>
178 template <
class T,
unsigned N>
191 template <
class T,
unsigned N>
192 template <
class Rep,
class Period>
195 int timeout_ms_clamped =
196 static_cast<int>(std::min(std::chrono::milliseconds(timeout).count(),
197 static_cast<std::chrono::milliseconds::rep
>(std::numeric_limits<int>::max())));
205 template <
class T,
unsigned N>
214 template <
class T,
unsigned N>
223 template <
class T,
unsigned N>
232 template <
class T,
unsigned N>
241 template <
class T,
unsigned N>
250 template <
class T,
unsigned N>
259 template <
class T,
unsigned N>
269 template <
class T,
unsigned N>
278 template <
class T,
unsigned N>
An RTOS queue class.
Definition: static_queue.h:98
bool SendFromIsr(const T &data)
Add to a queue from an interrupt service routine.
Definition: static_queue.h:168
~StaticQueue()
Destroy a queue.
Definition: static_queue.h:144
bool Reset()
Resets queue to empty state.
Definition: static_queue.h:215
bool ReceiveFromIsr(T &data)
Get an item from the queue from an interrupt context.
Definition: static_queue.h:206
bool IsEmpty() const
Check if a queue is empty.
Definition: static_queue.h:224
bool IsEmptyFromIsr() const
Check if a queue is empty from an interrupt service routine.
Definition: static_queue.h:233
bool IsFullFromIsr() const
Check if a queue is full from an interrupt service routine.
Definition: static_queue.h:251
bool Send(const T &data, int timeout_ms=ETCPAL_WAIT_FOREVER)
Add some data to the queue.
Definition: static_queue.h:159
bool Receive(T &data, int timeout_ms=ETCPAL_WAIT_FOREVER)
Get an item from the queue.
Definition: static_queue.h:179
size_t SlotsUsedFromIsr() const
Get number of slots being stored in the queue from an interrupt service routine.
Definition: static_queue.h:270
size_t SlotsUsed() const
Get number of slots being stored in the queue.
Definition: static_queue.h:260
size_t SlotsAvailable() const
Get number of remaining slots in the queue.
Definition: static_queue.h:279
bool IsFull() const
Check if a queue is full.
Definition: static_queue.h:242
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_create_static(etcpal_queue_t *id, size_t size, size_t item_size, uint8_t *buffer)
Create a new queue with a buffer provided by the user.
Definition: queue.c:184
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
#define ETCPAL_WAIT_FOREVER
For etcpal_ functions that take a millisecond timeout, this means to wait indefinitely.
Definition: common.h:118