SuperTinyKernel™ RTOS 1.08.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
stk::sync::MessageQueue Class Reference

Fixed-capacity, fixed-message-size FIFO queue for inter-task communication. More...

#include <stk_sync_msgqueue.h>

Inheritance diagram for stk::sync::MessageQueue:
Collaboration diagram for stk::sync::MessageQueue:

Public Member Functions

 MessageQueue (uint8_t *buf, size_t capacity, size_t msg_size)
 Constructor.
 ~MessageQueue ()=default
 Destructor.
bool Put (const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
 Put a message into the back of the queue (FIFO order).
bool TryPut (const void *msg_ptr)
 Attempt to put a message into the back of the queue without blocking.
bool PutFront (const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
 Put a message into the front of the queue (LIFO / priority-insert order).
bool TryPutFront (const void *msg_ptr)
 Attempt to put a message into the front of the queue without blocking.
bool Get (void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
 Get a message from the queue.
bool TryGet (void *msg_ptr)
 Attempt to get a message from the queue without blocking.
bool Peek (void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
 Peek at the next message to be delivered (back of the FIFO) without removing it.
bool TryPeek (void *msg_ptr)
 Attempt to peek at the next message without blocking.
bool PeekFront (void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
 Peek at the most recently front-inserted message (front of the FIFO) without removing it.
bool TryPeekFront (void *msg_ptr)
 Attempt to peek at the front message without blocking.
void Reset ()
 Discard all messages and reset the queue to the empty state.
size_t GetCapacity () const
 Get the maximum number of messages the queue can hold.
size_t GetMsgSize () const
 Get the size of each message in bytes.
size_t GetCount () const
 Get the current number of messages in the queue.
size_t GetSpace () const
 Get the number of free slots currently available.
uint8_t * GetBuffer ()
 Get pointer to the message buffer.
bool IsEmpty () const
 Check whether the queue is currently empty.
bool IsFull () const
 Check whether the queue is currently full.
bool IsStorageValid () const
 Verify that the backing storage is valid and the pool is ready for use.
void SetTraceName (const char *name)
 Set name.
const char * GetTraceName () const
 Get name.

Static Public Attributes

static const size_t CAPACITY_MAX = 0xFFFEU
 Max capacity supported (number of messages).

Private Member Functions

 MessageQueue (const MessageQueue &)=delete
MessageQueueoperator= (const MessageQueue &)=delete
uint8_t * Slot (size_t idx) const
size_t Next (size_t idx) const
size_t Prev (size_t idx) const

Private Attributes

uint8_t * m_buffer
 flat byte ring-buffer: capacity slots of msg_size bytes each
const size_t m_capacity
 maximum number of messages stored in the queue
const size_t m_msg_size
 size of each message in bytes
size_t m_count
 current number of messages stored in the queue
size_t m_head
 write index (next slot to be written by Put())
size_t m_tail
 read index (next slot to be read by Get())
ConditionVariable m_cv_not_empty
 signaled by Put() when the queue transitions from empty
ConditionVariable m_cv_not_full
 signaled by Get()/Reset() when the queue is no longer full

Detailed Description

Fixed-capacity, fixed-message-size FIFO queue for inter-task communication.

MessageQueue provides a synchronized ring-buffer that transports opaque, fixed-size byte messages between tasks. It follows the following blocking semantics:

  • Put() blocks if the queue is full until space becomes available or the timeout expires.
  • Get() blocks if the queue is empty until a message is produced or the timeout expires.

Unlike stk::sync::Pipe, which is parameterised on an element type, MessageQueue is parameterised on a byte count (MSG). This makes it suitable for passing heterogeneous or C-ABI structs without requiring the message type to be copyable via the C++ assignment operator. The message payload is always copied with memcpy.

// Caller owns and provides the buffer (e.g. from a static pool):
struct SensorMsg { uint32_t timestamp_ms; int16_t value; };
static uint8_t s_buf[8 * sizeof(SensorMsg)];
stk::sync::MessageQueue g_SensorQ(s_buf, 8, sizeof(SensorMsg));
Fixed-capacity, fixed-message-size FIFO queue for inter-task communication.
Note
The caller is responsible for ensuring that buf remains valid for the entire lifetime of the queue object.
Maximum number of messages (capacity) must not exceed CAPACITY_MAX.
Message size (msg_size) must be at least 1.
See also
MessageQueueT, Pipe, ConditionVariable, Semaphore
Note
Only available when kernel is compiled with KERNEL_SYNC mode enabled.

Definition at line 55 of file stk_sync_msgqueue.h.

Constructor & Destructor Documentation

◆ MessageQueue() [1/2]

stk::sync::MessageQueue::MessageQueue ( uint8_t * buf,
size_t capacity,
size_t msg_size )
inlineexplicit

Constructor.

Parameters
[in]bufPointer to the externally-allocated storage. Must be at least capacity * msg_size bytes.
[in]capacityMaximum number of messages [1, CAPACITY_MAX].
[in]msg_sizeSize of each message in bytes (>= 1).

Definition at line 304 of file stk_sync_msgqueue.h.

305: m_buffer(buf),
306 m_capacity(capacity),
307 m_msg_size(msg_size),
308 m_count(0U),
309 m_head(0U),
310 m_tail(0U)
311{
312 STK_ASSERT(buf != nullptr);
313 STK_ASSERT(capacity >= 1U);
314 STK_ASSERT(capacity <= CAPACITY_MAX);
315 STK_ASSERT(msg_size >= 1U);
316}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:455
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
size_t m_tail
read index (next slot to be read by Get())
const size_t m_capacity
maximum number of messages stored in the queue
size_t m_head
write index (next slot to be written by Put())
uint8_t * m_buffer
flat byte ring-buffer: capacity slots of msg_size bytes each
size_t m_count
current number of messages stored in the queue
const size_t m_msg_size
size of each message in bytes

References CAPACITY_MAX, m_buffer, m_capacity, m_count, m_head, m_msg_size, m_tail, and STK_ASSERT.

Referenced by MessageQueue(), and stk::sync::MessageQueueT< N, MSG >::MessageQueueT().

Here is the caller graph for this function:

◆ ~MessageQueue()

stk::sync::MessageQueue::~MessageQueue ( )
default

Destructor.

Note
If tasks are still waiting at destruction time it is considered a logical error (dangling waiters). An assertion is triggered in debug builds via the ConditionVariable destructors.
MISRA deviation: [STK-DEV-005] Rule 10-3-2.

References STK_VIRT_DTOR, and stk::WAIT_INFINITE.

◆ MessageQueue() [2/2]

stk::sync::MessageQueue::MessageQueue ( const MessageQueue & )
privatedelete

References MessageQueue().

Here is the call graph for this function:

Member Function Documentation

◆ Get()

bool stk::sync::MessageQueue::Get ( void * msg_ptr,
Timeout timeout_ticks = WAIT_INFINITE )
inline

Get a message from the queue.

Copies msg_size bytes from the oldest slot in the ring buffer into the buffer pointed to by msg_ptr. If the queue is empty the calling task is suspended until a message is produced or the timeout expires.

Parameters
[out]msg_ptrDestination buffer for the retrieved message (must be at least msg_size bytes).
[in]timeout_ticksMaximum time to wait for a message (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT for a non-blocking attempt.
Warning
ISR-safe only with timeout_ticks = NO_WAIT, ISR-unsafe otherwise.
Returns
true if a message was successfully retrieved, false if the timeout expired before a message was available.

Definition at line 391 of file stk_sync_msgqueue.h.

392{
393 STK_ASSERT(msg_ptr != nullptr); // API contract: msg_ptr must not be null
394
395 ScopedCriticalSection cs_;
396 bool success = true;
397
398 while (m_count == 0U)
399 {
400 if (!m_cv_not_empty.Wait(cs_, timeout_ticks))
401 {
402 success = false;
403 break;
404 }
405 }
406
407 if (success)
408 {
409 STK_MEMCPY(msg_ptr, Slot(m_tail), m_msg_size);
410 m_tail = Next(m_tail);
411 m_count--;
412
413 m_cv_not_full.NotifyOne_CS();
414 }
415
416 return success;
417}
static void STK_MEMCPY(void *const dest, const void *const src, const size_t size)
Implementation of STK_MEMCPY.
Definition stk_arch.h:623
size_t Next(size_t idx) const
uint8_t * Slot(size_t idx) const
ConditionVariable m_cv_not_full
signaled by Get()/Reset() when the queue is no longer full
ConditionVariable m_cv_not_empty
signaled by Put() when the queue transitions from empty

References m_count, m_cv_not_empty, m_cv_not_full, m_msg_size, m_tail, Next(), Slot(), STK_ASSERT, and STK_MEMCPY().

Referenced by stk_msgq_get(), TryGet(), xMessageBufferReceive(), and xQueueSelectFromSet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBuffer()

uint8_t * stk::sync::MessageQueue::GetBuffer ( )
inline

Get pointer to the message buffer.

Returns
Pointer to the beginning of the message buffer.
Note
ISR-safe.

Definition at line 253 of file stk_sync_msgqueue.h.

253{ return m_buffer; }

References m_buffer.

Referenced by osMessageQueueNew(), and stk_msgq_get_buffer().

Here is the caller graph for this function:

◆ GetCapacity()

size_t stk::sync::MessageQueue::GetCapacity ( ) const
inline

Get the maximum number of messages the queue can hold.

Returns
Construction-time capacity.
Note
ISR-safe.

Definition at line 228 of file stk_sync_msgqueue.h.

228{ return m_capacity; }

References m_capacity.

Referenced by osMessageQueueGetCapacity(), and stk_msgq_get_capacity().

Here is the caller graph for this function:

◆ GetCount()

size_t stk::sync::MessageQueue::GetCount ( ) const
inline

Get the current number of messages in the queue.

Returns
Point-in-time snapshot of the message count. May be stale by the time the caller acts on it in a multi-task environment.
Note
ISR-safe on targets where a size_t-aligned read is atomic.

Definition at line 241 of file stk_sync_msgqueue.h.

241{ return m_count; }

References m_count.

Referenced by osMessageQueueGetCount(), stk_msgq_get_count(), uxQueueMessagesWaiting(), and uxQueueMessagesWaitingFromISR().

Here is the caller graph for this function:

◆ GetMsgSize()

size_t stk::sync::MessageQueue::GetMsgSize ( ) const
inline

Get the size of each message in bytes.

Returns
Construction-time message size.
Note
ISR-safe.

Definition at line 234 of file stk_sync_msgqueue.h.

234{ return m_msg_size; }

References m_msg_size.

Referenced by osMessageQueueGetMsgSize(), and stk_msgq_get_msg_size().

Here is the caller graph for this function:

◆ GetSpace()

size_t stk::sync::MessageQueue::GetSpace ( ) const
inline

Get the number of free slots currently available.

Returns
Point-in-time snapshot of the free-slot count.
Note
ISR-safe.

Definition at line 247 of file stk_sync_msgqueue.h.

247{ return (m_capacity - m_count); }

References m_capacity, and m_count.

Referenced by osMessageQueueGetSpace(), stk_msgq_get_space(), and uxQueueSpacesAvailable().

Here is the caller graph for this function:

◆ GetTraceName()

const char * stk::ITraceable::GetTraceName ( ) const
inlineinherited

Get name.

Returns
Name string, or NULL if not set or if STK_SYNC_DEBUG_NAMES is 0.

Definition at line 515 of file stk_common.h.

516 {
517 #if STK_SYNC_DEBUG_NAMES
518 return m_trace_name;
519 #else
520 return nullptr;
521 #endif
522 }

◆ IsEmpty()

bool stk::sync::MessageQueue::IsEmpty ( ) const
inline

Check whether the queue is currently empty.

Returns
true if the queue contains no messages.
Note
ISR-safe.

Definition at line 259 of file stk_sync_msgqueue.h.

259{ return (m_count == 0U); }

References m_count.

Referenced by stk_msgq_is_empty(), xQueueAddToSet(), and xQueueRemoveFromSet().

Here is the caller graph for this function:

◆ IsFull()

bool stk::sync::MessageQueue::IsFull ( ) const
inline

Check whether the queue is currently full.

Returns
true if the queue contains capacity messages.
Note
ISR-safe.

Definition at line 265 of file stk_sync_msgqueue.h.

265{ return (m_count == m_capacity); }

References m_capacity, and m_count.

Referenced by stk_msgq_is_full().

Here is the caller graph for this function:

◆ IsStorageValid()

bool stk::sync::MessageQueue::IsStorageValid ( ) const
inline

Verify that the backing storage is valid and the pool is ready for use.

Always true for pools constructed with external storage. For heap-constructed queue, false if operator new failed. Must be checked after the heap constructor when operating without exceptions (the typical embedded configuration).

Returns
true if the queue is ready for use.
Note
ISR-safe.

Definition at line 275 of file stk_sync_msgqueue.h.

275{ return (m_buffer != nullptr); }

References m_buffer.

Referenced by stk_msgq_is_storage_valid(), xMessageBufferCreate(), xMessageBufferCreateWithCallback(), and xQueueCreate().

Here is the caller graph for this function:

◆ Next()

size_t stk::sync::MessageQueue::Next ( size_t idx) const
inlineprivate

Definition at line 284 of file stk_sync_msgqueue.h.

284{ return (idx + 1U) % m_capacity; }

References m_capacity.

Referenced by Get(), and Put().

Here is the caller graph for this function:

◆ operator=()

MessageQueue & stk::sync::MessageQueue::operator= ( const MessageQueue & )
privatedelete

◆ Peek()

bool stk::sync::MessageQueue::Peek ( void * msg_ptr,
Timeout timeout_ticks = WAIT_INFINITE )
inline

Peek at the next message to be delivered (back of the FIFO) without removing it.

Copies msg_size bytes from the oldest slot in the ring buffer into the buffer pointed to by msg_ptr, leaving the message in place so that a subsequent Get() will return the same message. If the queue is empty the calling task is suspended until a message is produced or the timeout expires.

Parameters
[out]msg_ptrDestination buffer for the peeked message (must be at least msg_size bytes).
[in]timeout_ticksMaximum time to wait for a message (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT for a non-blocking attempt.
Warning
ISR-safe only with timeout_ticks = NO_WAIT, ISR-unsafe otherwise.
Returns
true if a message was successfully peeked, false if the timeout expired before a message was available.
See also
Get, TryPeek, PeekFront

Definition at line 423 of file stk_sync_msgqueue.h.

424{
425 STK_ASSERT(msg_ptr != nullptr); // API contract: msg_ptr must not be null
426
427 ScopedCriticalSection cs_;
428 bool success = true;
429
430 while (m_count == 0U)
431 {
432 if (!m_cv_not_empty.Wait(cs_, timeout_ticks))
433 {
434 success = false;
435 break;
436 }
437 }
438
439 if (success)
440 {
441 // copy from the tail slot without advancing the index or decrementing
442 // the count, so the message remains available for the next Get()
443 STK_MEMCPY(msg_ptr, Slot(m_tail), m_msg_size);
444 }
445
446 return success;
447}

References m_count, m_cv_not_empty, m_msg_size, m_tail, Slot(), STK_ASSERT, and STK_MEMCPY().

Referenced by stk_msgq_peek(), and TryPeek().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PeekFront()

bool stk::sync::MessageQueue::PeekFront ( void * msg_ptr,
Timeout timeout_ticks = WAIT_INFINITE )
inline

Peek at the most recently front-inserted message (front of the FIFO) without removing it.

Copies msg_size bytes from the slot immediately before the current write pointer (i.e. the message that PutFront() most recently placed) into the buffer pointed to by msg_ptr, leaving the message in place. If the queue is empty the calling task is suspended until a message is produced or the timeout expires.

Parameters
[out]msg_ptrDestination buffer for the peeked message (must be at least msg_size bytes).
[in]timeout_ticksMaximum time to wait for a message (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT for a non-blocking attempt.
Warning
ISR-safe only with timeout_ticks= NO_WAIT, ISR-unsafe otherwise.
Returns
true if a message was successfully peeked, false if the timeout expired before a message was available.
See also
PutFront, TryPeekFront, Peek

Definition at line 453 of file stk_sync_msgqueue.h.

454{
455 STK_ASSERT(msg_ptr != nullptr); // API contract: msg_ptr must not be null
456
457 ScopedCriticalSection cs_;
458 bool success = true;
459
460 while (m_count == 0U)
461 {
462 if (!m_cv_not_empty.Wait(cs_, timeout_ticks))
463 {
464 success = false;
465 break;
466 }
467 }
468
469 if (success)
470 {
471 // the front-inserted message is at m_tail (PutFront retreats m_tail then
472 // writes, so the newly placed message is always at the current m_tail);
473 // for a pure-Put queue this is equally correct: m_tail is the oldest slot
474 STK_MEMCPY(msg_ptr, Slot(m_tail), m_msg_size);
475 }
476
477 return success;
478}

References m_count, m_cv_not_empty, m_msg_size, m_tail, Slot(), STK_ASSERT, and STK_MEMCPY().

Referenced by stk_msgq_peekfront(), and TryPeekFront().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Prev()

size_t stk::sync::MessageQueue::Prev ( size_t idx) const
inlineprivate

Definition at line 288 of file stk_sync_msgqueue.h.

288{ return (idx == 0U) ? (m_capacity - 1U) : (idx - 1U); }

References m_capacity.

Referenced by PutFront().

Here is the caller graph for this function:

◆ Put()

bool stk::sync::MessageQueue::Put ( const void * msg_ptr,
Timeout timeout_ticks = WAIT_INFINITE )
inline

Put a message into the back of the queue (FIFO order).

Copies msg_size bytes from msg_ptr into the next available slot in the ring buffer. If the queue is full the calling task is suspended until space becomes available or the timeout expires.

Parameters
[in]msg_ptrPointer to the message payload (must be at least msg_size bytes).
[in]timeout_ticksMaximum time to wait for a free slot (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT for a non-blocking attempt.
Warning
ISR-safe only with timeout_ticks = NO_WAIT, ISR-unsafe otherwise.
Returns
true if the message was successfully enqueued, false if the timeout expired before space became available.

Definition at line 322 of file stk_sync_msgqueue.h.

323{
324 STK_ASSERT(msg_ptr != nullptr); // API contract: msg_ptr must not be null
325 STK_ASSERT(m_count <= (CAPACITY_MAX - 1U)); // API contract: must not exceed capacity
326
327 ScopedCriticalSection cs_;
328 bool success = true;
329
330 while (m_count == m_capacity)
331 {
332 if (!m_cv_not_full.Wait(cs_, timeout_ticks))
333 {
334 success = false;
335 break;
336 }
337 }
338
339 if (success)
340 {
341 STK_MEMCPY(Slot(m_head), msg_ptr, m_msg_size);
342 m_head = Next(m_head);
343 m_count++;
344
345 m_cv_not_empty.NotifyOne_CS();
346 }
347
348 return success;
349}

References CAPACITY_MAX, m_capacity, m_count, m_cv_not_empty, m_cv_not_full, m_head, m_msg_size, Next(), Slot(), STK_ASSERT, and STK_MEMCPY().

Referenced by stk_msgq_put(), TryPut(), xMessageBufferSend(), and xQueueSend().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PutFront()

bool stk::sync::MessageQueue::PutFront ( const void * msg_ptr,
Timeout timeout_ticks = WAIT_INFINITE )
inline

Put a message into the front of the queue (LIFO / priority-insert order).

Copies msg_size bytes from msg_ptr into the slot immediately before the current read pointer, making it the next message that Get() will return. If the queue is full the calling task is suspended until space becomes available or the timeout expires.

Parameters
[in]msg_ptrPointer to the message payload (must be at least msg_size bytes).
[in]timeout_ticksMaximum time to wait for a free slot (ticks). Use WAIT_INFINITE to block indefinitely, NO_WAIT for a non-blocking attempt.
Warning
ISR-safe only with timeout_ticks = NO_WAIT, ISR-unsafe otherwise.
Returns
true if the message was successfully enqueued at the front, false if the timeout expired before space became available.
See also
Put, TryPutFront

Definition at line 355 of file stk_sync_msgqueue.h.

356{
357 STK_ASSERT(msg_ptr != nullptr); // API contract: msg_ptr must not be null
358 STK_ASSERT(m_count <= (CAPACITY_MAX - 1U)); // API contract: must not exceed capacity
359
360 ScopedCriticalSection cs_;
361 bool success = true;
362
363 while (m_count == m_capacity)
364 {
365 if (!m_cv_not_full.Wait(cs_, timeout_ticks))
366 {
367 success = false;
368 break;
369 }
370 }
371
372 if (success)
373 {
374 // retreat the tail pointer to claim the slot that Get() would read next,
375 // then write the message there; this makes the new message the head of
376 // the logical sequence without touching m_head at all
377 m_tail = Prev(m_tail);
378 STK_MEMCPY(Slot(m_tail), msg_ptr, m_msg_size);
379 m_count++;
380
381 m_cv_not_empty.NotifyOne_CS();
382 }
383
384 return success;
385}
size_t Prev(size_t idx) const

References CAPACITY_MAX, m_capacity, m_count, m_cv_not_empty, m_cv_not_full, m_msg_size, m_tail, Prev(), Slot(), STK_ASSERT, and STK_MEMCPY().

Referenced by stk_msgq_putfront(), TryPutFront(), and xQueueSendToFront().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reset()

void stk::sync::MessageQueue::Reset ( )
inline

Discard all messages and reset the queue to the empty state.

Resets the head, tail and count to zero. Any tasks blocked in Put() are woken so they can re-evaluate and enqueue their messages into the now-empty queue.

Warning
Messages that were in the queue are silently discarded. Ensure no consumers depend on them before calling Reset().
ISR-safe.

Definition at line 484 of file stk_sync_msgqueue.h.

485{
486 const ScopedCriticalSection cs_;
487
488 m_count = 0U;
489 m_head = 0U;
490 m_tail = 0U;
491
492 // wake all blocked producers: the queue is now entirely empty
493 m_cv_not_full.NotifyAll_CS();
494}

References m_count, m_cv_not_full, m_head, and m_tail.

Referenced by stk_msgq_reset(), xMessageBufferReset(), xMessageBufferResetFromISR(), xQueueOverwrite(), and xQueueOverwriteFromISR().

Here is the caller graph for this function:

◆ SetTraceName()

void stk::ITraceable::SetTraceName ( const char * name)
inlineinherited

Set name.

Parameters
[in]nameNull-terminated string or NULL.
Note
If STK_SYNC_DEBUG_NAMES is 0 then calling this function has no effect.

Definition at line 503 of file stk_common.h.

504 {
505 #if STK_SYNC_DEBUG_NAMES
506 m_trace_name = name;
507 #else
508 STK_UNUSED(name);
509 #endif
510 }
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
Definition stk_defs.h:654

References STK_UNUSED.

Referenced by stk::memory::BlockMemoryPool::BlockMemoryPool(), and stk::memory::BlockMemoryPool::BlockMemoryPool().

Here is the caller graph for this function:

◆ Slot()

uint8_t * stk::sync::MessageQueue::Slot ( size_t idx) const
inlineprivate

Definition at line 281 of file stk_sync_msgqueue.h.

281{ return m_buffer + (idx * m_msg_size); }

References m_buffer, and m_msg_size.

Referenced by Get(), Peek(), PeekFront(), Put(), and PutFront().

Here is the caller graph for this function:

◆ TryGet()

bool stk::sync::MessageQueue::TryGet ( void * msg_ptr)
inline

Attempt to get a message from the queue without blocking.

Dequeues a message only if one is immediately available. Returns false instantly if the queue is empty.

Parameters
[out]msg_ptrDestination buffer for the retrieved message.
Warning
ISR-safe.
Returns
true if a message was retrieved, false if the queue was empty.

Definition at line 154 of file stk_sync_msgqueue.h.

154{ return Get(msg_ptr, NO_WAIT); }
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:214
bool Get(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Get a message from the queue.

References Get(), and stk::NO_WAIT.

Referenced by stk_msgq_tryget(), xMessageBufferReceiveFromISR(), xMessageBufferReset(), xMessageBufferResetFromISR(), and xQueueSelectFromSetFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryPeek()

bool stk::sync::MessageQueue::TryPeek ( void * msg_ptr)
inline

Attempt to peek at the next message without blocking.

Copies the oldest message into msg_ptr only if one is immediately available. The message is not removed from the queue. Returns false instantly if the queue is empty.

Parameters
[out]msg_ptrDestination buffer for the peeked message.
Warning
ISR-safe.
Returns
true if a message was peeked, false if the queue was empty.
See also
Peek, TryGet

Definition at line 183 of file stk_sync_msgqueue.h.

183{ return Peek(msg_ptr, NO_WAIT); }
bool Peek(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the next message to be delivered (back of the FIFO) without removing it.

References stk::NO_WAIT, and Peek().

Referenced by stk_msgq_trypeek(), and xMessageBufferNextLengthBytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryPeekFront()

bool stk::sync::MessageQueue::TryPeekFront ( void * msg_ptr)
inline

Attempt to peek at the front message without blocking.

Copies the most recently front-inserted message into msg_ptr only if one is immediately available. The message is not removed from the queue. Returns false instantly if the queue is empty.

Parameters
[out]msg_ptrDestination buffer for the peeked message.
Warning
ISR-safe.
Returns
true if a message was peeked, false if the queue was empty.
See also
PeekFront, TryPutFront

Definition at line 212 of file stk_sync_msgqueue.h.

212{ return PeekFront(msg_ptr, NO_WAIT); }
bool PeekFront(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Peek at the most recently front-inserted message (front of the FIFO) without removing it.

References stk::NO_WAIT, and PeekFront().

Referenced by stk_msgq_trypeekfront().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryPut()

bool stk::sync::MessageQueue::TryPut ( const void * msg_ptr)
inline

Attempt to put a message into the back of the queue without blocking.

Enqueues the message only if a free slot is immediately available. Returns false instantly if the queue is full.

Parameters
[in]msg_ptrPointer to the message payload.
Warning
ISR-safe.
Returns
true if the message was enqueued, false if the queue was full.

Definition at line 101 of file stk_sync_msgqueue.h.

101{ return Put(msg_ptr, NO_WAIT); }
bool Put(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the back of the queue (FIFO order).

References stk::NO_WAIT, and Put().

Referenced by stk_msgq_tryput(), xMessageBufferReceive(), xMessageBufferSendFromISR(), xQueueOverwrite(), xQueueOverwriteFromISR(), and xQueueSendFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryPutFront()

bool stk::sync::MessageQueue::TryPutFront ( const void * msg_ptr)
inline

Attempt to put a message into the front of the queue without blocking.

Enqueues the message at the front only if a free slot is immediately available. Returns false instantly if the queue is full.

Parameters
[in]msg_ptrPointer to the message payload.
Warning
ISR-safe.
Returns
true if the message was enqueued at the front, false if the queue was full.
See also
TryPut, PutFront

Definition at line 128 of file stk_sync_msgqueue.h.

128{ return PutFront(msg_ptr, NO_WAIT); }
bool PutFront(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the front of the queue (LIFO / priority-insert order).

References stk::NO_WAIT, and PutFront().

Referenced by stk_msgq_tryputfront(), xMessageBufferReceiveFromISR(), and xQueueSendToFrontFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ CAPACITY_MAX

const size_t stk::sync::MessageQueue::CAPACITY_MAX = 0xFFFEU
static

Max capacity supported (number of messages).

Definition at line 60 of file stk_sync_msgqueue.h.

Referenced by MessageQueue(), osMessageQueueNew(), Put(), PutFront(), xQueueCreate(), xQueueCreateSet(), and xQueueCreateStatic().

◆ m_buffer

uint8_t* stk::sync::MessageQueue::m_buffer
private

flat byte ring-buffer: capacity slots of msg_size bytes each

Definition at line 290 of file stk_sync_msgqueue.h.

Referenced by GetBuffer(), IsStorageValid(), MessageQueue(), and Slot().

◆ m_capacity

const size_t stk::sync::MessageQueue::m_capacity
private

maximum number of messages stored in the queue

Definition at line 291 of file stk_sync_msgqueue.h.

Referenced by GetCapacity(), GetSpace(), IsFull(), MessageQueue(), Next(), Prev(), Put(), and PutFront().

◆ m_count

size_t stk::sync::MessageQueue::m_count
private

current number of messages stored in the queue

Definition at line 293 of file stk_sync_msgqueue.h.

Referenced by Get(), GetCount(), GetSpace(), IsEmpty(), IsFull(), MessageQueue(), Peek(), PeekFront(), Put(), PutFront(), and Reset().

◆ m_cv_not_empty

ConditionVariable stk::sync::MessageQueue::m_cv_not_empty
private

signaled by Put() when the queue transitions from empty

Definition at line 296 of file stk_sync_msgqueue.h.

Referenced by Get(), Peek(), PeekFront(), Put(), and PutFront().

◆ m_cv_not_full

ConditionVariable stk::sync::MessageQueue::m_cv_not_full
private

signaled by Get()/Reset() when the queue is no longer full

Definition at line 297 of file stk_sync_msgqueue.h.

Referenced by Get(), Put(), PutFront(), and Reset().

◆ m_head

size_t stk::sync::MessageQueue::m_head
private

write index (next slot to be written by Put())

Definition at line 294 of file stk_sync_msgqueue.h.

Referenced by MessageQueue(), Put(), and Reset().

◆ m_msg_size

const size_t stk::sync::MessageQueue::m_msg_size
private

size of each message in bytes

Definition at line 292 of file stk_sync_msgqueue.h.

Referenced by Get(), GetMsgSize(), MessageQueue(), Peek(), PeekFront(), Put(), PutFront(), and Slot().

◆ m_tail

size_t stk::sync::MessageQueue::m_tail
private

read index (next slot to be read by Get())

Definition at line 295 of file stk_sync_msgqueue.h.

Referenced by Get(), MessageQueue(), Peek(), PeekFront(), PutFront(), and Reset().


The documentation for this class was generated from the following file: