![]() |
SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Thread-safe, type-safe FIFO communication pipe with internal storage. More...
#include <stk_sync_pipe.h>
Public Member Functions | |
| PipeT () | |
| Constructor. | |
| bool | Write (const T &data, Timeout timeout_ticks=WAIT_INFINITE) |
| Write data to the pipe. | |
| bool | TryWrite (const T &data) |
| Attempt to write data to the pipe without blocking. | |
| size_t | WriteBulk (const T *src, size_t count, Timeout timeout_ticks=WAIT_INFINITE) |
| Write multiple elements to the pipe. | |
| size_t | TryWriteBulk (const T *src, size_t count) |
| Attempt to write multiple elements to the pipe without blocking. | |
| bool | Read (T &data, Timeout timeout_ticks=WAIT_INFINITE) |
| Read data from the pipe. | |
| bool | TryRead (T &data) |
| Attempt to read data from the pipe without blocking. | |
| size_t | ReadBulk (T *dst, size_t count, Timeout timeout_ticks=WAIT_INFINITE) |
| Read multiple elements from the pipe. | |
| size_t | TryReadBulk (T *dst, size_t count) |
| Attempt to read multiple elements from the pipe without blocking. | |
| void | Reset () |
| Discard all elements and reset the pipe to the empty state. | |
| size_t | GetCapacity () const |
| Get the maximum number of elements the pipe can hold. | |
| size_t | GetCount () const |
| Get the current number of elements in the pipe. | |
| size_t | GetSpace () const |
| Get the number of free slots currently available. | |
| bool | IsEmpty () const |
| Check if the pipe is currently empty. | |
| bool | IsFull () const |
| Check if the pipe is currently full. | |
Private Member Functions | |
| PipeT (const PipeT &)=delete | |
| PipeT & | operator= (const PipeT &)=delete |
Private Attributes | |
| T | m_buffer [N] |
| static storage for FIFO elements | |
| size_t | m_head |
| index of the next slot to be written (producer) | |
| size_t | m_tail |
| index of the next slot to be read (consumer) | |
| size_t | m_count |
| current number of elements stored in the pipe | |
| ConditionVariable | m_cv_not_empty |
| condition variable signaled when the pipe is no longer empty | |
| ConditionVariable | m_cv_not_full |
| condition variable signaled when the pipe is no longer full | |
Thread-safe, type-safe FIFO communication pipe with internal storage.
| T | Data type of elements. |
| N | Capacity of the pipe (number of elements). |
PipeT provides a synchronized ring-buffer mechanism that allows tasks to exchange typed data safely. It implements blocking semantics:
Write() blocks if the pipe is full until space becomes available.Read() blocks if the pipe is empty until data is produced.Unlike stk::sync::Pipe, which operates on raw byte buffers and uses memcpy for all transfers, PipeT is parameterised on a concrete element type T. This enables:
memcpy overhead for scalar types).N and element size, allowing the compiler to strength-reduce modulo operations and eliminate dead branches in bulk transfer paths.T references and pointers.Definition at line 671 of file stk_sync_pipe.h.
|
inlineexplicit |
Constructor.
Definition at line 676 of file stk_sync_pipe.h.
|
privatedelete |
|
inline |
Get the maximum number of elements the pipe can hold.
N. Definition at line 1023 of file stk_sync_pipe.h.
|
inline |
Get the current number of elements in the pipe.
Definition at line 1030 of file stk_sync_pipe.h.
|
inline |
Get the number of free slots currently available.
Definition at line 1036 of file stk_sync_pipe.h.
|
inline |
Check if the pipe is currently empty.
true if empty, otherwise false. Definition at line 1043 of file stk_sync_pipe.h.
|
inline |
Check if the pipe is currently full.
true if full, otherwise false. Definition at line 1050 of file stk_sync_pipe.h.
|
privatedelete |
|
inline |
Read data from the pipe.
Attempts to retrieve an element from the FIFO queue. If pipe is empty, the calling task will be suspended until data is provided by a producer or the timeout expires.
| [out] | data | Reference to the variable where the retrieved data will be stored. |
| [in] | timeout_ticks | Maximum time to wait for data (ticks). Default: WAIT_INFINITE. |
true if data was successfully read, false if timeout expired before any data became available. Definition at line 849 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::TryRead().
|
inline |
Read multiple elements from the pipe.
Attempts to retrieve a block of data from the FIFO. If pipe does not contain enough elements to satisfy the requested count, it will block until the full amount is read or the timeout expires.
| [out] | dst | Pointer to the destination array. |
| [in] | count | Number of elements to read. |
| [in] | timeout_ticks | Maximum time to wait for data (ticks). Default: WAIT_INFINITE. |
count unless a timeout occurred. Definition at line 906 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::TryReadBulk().
|
inline |
Discard all elements and reset the pipe to the empty state.
Resets head, tail and count to zero. Any tasks blocked in Write() are woken so they can re-evaluate and enqueue into the now-empty pipe.
Definition at line 1006 of file stk_sync_pipe.h.
|
inline |
Attempt to read data from the pipe without blocking.
Dequeues an element only if one is immediately available. Returns false instantly if the pipe is empty.
| [out] | data | Reference to the variable where the retrieved data will be stored. |
true if data was successfully read, false if the pipe was empty. Definition at line 883 of file stk_sync_pipe.h.
|
inline |
Attempt to read multiple elements from the pipe without blocking.
Reads as many elements as are currently available without blocking.
| [out] | dst | Pointer to the destination array. |
| [in] | count | Number of elements to read. |
Definition at line 997 of file stk_sync_pipe.h.
|
inline |
Attempt to write data to the pipe without blocking.
Enqueues the element only if a free slot is immediately available. Returns false instantly if the pipe is full.
| [in] | data | Reference to the data element to be copied into the pipe. |
true if data was successfully written, false if no space is available. Definition at line 723 of file stk_sync_pipe.h.
|
inline |
Attempt to write multiple elements to the pipe without blocking.
Copies as many elements as possible without blocking. Elements that do not fit are discarded.
| [in] | src | Pointer to the source array. |
| [in] | count | Number of elements to write. |
Definition at line 837 of file stk_sync_pipe.h.
|
inline |
Write data to the pipe.
Attempts to push an element into the FIFO queue. If pipe is full, the calling task will be suspended until space is made available by a consumer or the timeout expires.
| [in] | data | Reference to the data element to be copied into the pipe. |
| [in] | timeout_ticks | Maximum time to wait for space (ticks). Default: WAIT_INFINITE. |
true if data was successfully written, false if timeout expired before space became available. Definition at line 689 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::TryWrite().
|
inline |
Write multiple elements to the pipe.
Copies a block of data into the FIFO. If the pipe does not have enough space for the entire block, it will block until the full amount can be written or the timeout expires.
| [in] | src | Pointer to the source array. |
| [in] | count | Number of elements to write. |
| [in] | timeout_ticks | Maximum time to wait for sufficient space (ticks). Default: WAIT_INFINITE. |
count unless a timeout occurred. Definition at line 745 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::TryWriteBulk().
|
private |
static storage for FIFO elements
Definition at line 1055 of file stk_sync_pipe.h.
|
private |
current number of elements stored in the pipe
Definition at line 1058 of file stk_sync_pipe.h.
|
private |
condition variable signaled when the pipe is no longer empty
Definition at line 1059 of file stk_sync_pipe.h.
|
private |
condition variable signaled when the pipe is no longer full
Definition at line 1060 of file stk_sync_pipe.h.
|
private |
index of the next slot to be written (producer)
Definition at line 1056 of file stk_sync_pipe.h.
|
private |
index of the next slot to be read (consumer)
Definition at line 1057 of file stk_sync_pipe.h.