|
SuperTinyKernel™ RTOS 1.08.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. | |
| EWaitResult | WriteEx (const T &data, Timeout timeout_ticks=WAIT_INFINITE) |
| Write data to the pipe, preserving the full wait outcome. | |
| 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. | |
| EWaitResult | WriteBulkEx (const T *src, size_t count, size_t &written, Timeout timeout_ticks=WAIT_INFINITE) |
| Write multiple elements to the pipe, preserving the full wait outcome. | |
| 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. | |
| EWaitResult | ReadEx (T &data, Timeout timeout_ticks=WAIT_INFINITE) |
| Read data from the pipe, preserving the full wait outcome. | |
| 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. | |
| EWaitResult | ReadBulkEx (T *dst, size_t count, size_t &read_count, Timeout timeout_ticks=WAIT_INFINITE) |
| Read multiple elements from the pipe, preserving the full wait outcome. | |
| 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.Write(), Read(), WriteBulk(), ReadBulk()) collapse a timeout and a cancellation (IKernel::CancelTaskWait()) into the same failure result. Use the *Ex() variants (WriteEx(), ReadEx(), WriteBulkEx(), ReadBulkEx()) if the caller needs to tell them apart.Definition at line 848 of file stk_sync_pipe.h.
|
inlineexplicit |
Constructor.
Definition at line 853 of file stk_sync_pipe.h.
|
privatedelete |
|
inline |
Get the maximum number of elements the pipe can hold.
N. Definition at line 1324 of file stk_sync_pipe.h.
|
inline |
Get the current number of elements in the pipe.
Definition at line 1331 of file stk_sync_pipe.h.
|
inline |
Get the number of free slots currently available.
Definition at line 1337 of file stk_sync_pipe.h.
|
inline |
Check if the pipe is currently empty.
true if empty, otherwise false. Definition at line 1344 of file stk_sync_pipe.h.
|
inline |
Check if the pipe is currently full.
true if full, otherwise false. Definition at line 1351 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 otherwise (timeout, cancellation or NO_WAIT on an empty pipe). Use ReadEx() to tell these apart. Definition at line 1145 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 or a cancellation occurred. Use ReadBulkEx() to tell these apart. Definition at line 1283 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::TryReadBulk().
|
inline |
Read multiple elements from the pipe, preserving the full wait outcome.
Identical to ReadBulk(), except the caller gets the raw EWaitResult and the number of elements read through read_count, so a cancellation (via IKernel::CancelTaskWait()) can be distinguished from a timeout. Elements already copied into dst before a timeout or cancellation stay valid and are counted.
| [out] | dst | Pointer to the destination array. |
| [in] | count | Number of elements to read. |
| [out] | read_count | Number of elements actually read (always set, 0 on WAIT_RESULT_FAIL). |
| [in] | timeout_ticks | Maximum time to wait for data (ticks). Default: WAIT_INFINITE. |
WAIT_RESULT_SIGNAL if all count elements were read (also for count = 0), WAIT_RESULT_TIMEOUT if the timeout expired (or NO_WAIT was passed) before all elements were available, WAIT_RESULT_CANCELED if the wait was cancelled via IKernel::CancelTaskWait(), WAIT_RESULT_FAIL if dst is nullptr or the kernel rejected the wait. On any non-signal result read_count holds the partial count. Definition at line 1175 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::ReadBulk().
|
inline |
Read data from the pipe, preserving the full wait outcome.
Identical to Read(), except the caller gets the raw EWaitResult, so a cancellation (via IKernel::CancelTaskWait()) can be distinguished from a timeout.
| [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. |
WAIT_RESULT_SIGNAL if an element was read, WAIT_RESULT_TIMEOUT if no data became available before the timeout expired (or NO_WAIT was passed on an empty pipe), WAIT_RESULT_CANCELED if the wait was cancelled via IKernel::CancelTaskWait(), WAIT_RESULT_FAIL if the kernel rejected the wait. data is not modified on a non-signal result. Definition at line 1091 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::Read().
|
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 1307 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 1157 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 1298 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 934 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 1077 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 otherwise (timeout, cancellation or NO_WAIT on a full pipe). Use WriteEx() to tell these apart. Definition at line 922 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 or a cancellation occurred. Use WriteBulkEx() to tell these apart. Definition at line 1061 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::TryWriteBulk().
|
inline |
Write multiple elements to the pipe, preserving the full wait outcome.
Identical to WriteBulk(), except the caller gets the raw EWaitResult and the number of elements written through written, so a cancellation (via IKernel::CancelTaskWait()) can be distinguished from a timeout. Elements already copied into the pipe before a timeout or cancellation stay in the pipe.
| [in] | src | Pointer to the source array. |
| [in] | count | Number of elements to write. |
| [out] | written | Number of elements actually written (always set, 0 on WAIT_RESULT_FAIL). |
| [in] | timeout_ticks | Maximum time to wait for sufficient space (ticks). Default: WAIT_INFINITE. |
WAIT_RESULT_SIGNAL if all count elements were written (also for count = 0), WAIT_RESULT_TIMEOUT if the timeout expired (or NO_WAIT was passed) before all elements fitted, WAIT_RESULT_CANCELED if the wait was cancelled via IKernel::CancelTaskWait(), WAIT_RESULT_FAIL if src is nullptr or the kernel rejected the wait. On any non-signal result written holds the partial count. Definition at line 952 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::WriteBulk().
|
inline |
Write data to the pipe, preserving the full wait outcome.
Identical to Write(), except the caller gets the raw EWaitResult, so a cancellation (via IKernel::CancelTaskWait()) can be distinguished from a timeout.
| [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. |
WAIT_RESULT_SIGNAL if data was written, WAIT_RESULT_TIMEOUT if no space became available before the timeout expired (or NO_WAIT was passed on a full pipe), WAIT_RESULT_CANCELED if the wait was cancelled via IKernel::CancelTaskWait(), WAIT_RESULT_FAIL if the kernel rejected the wait. Nothing is written on a non-signal result. Definition at line 868 of file stk_sync_pipe.h.
Referenced by stk::sync::PipeT< Timer *, 32U >::Write().
|
private |
static storage for FIFO elements
Definition at line 1356 of file stk_sync_pipe.h.
|
private |
current number of elements stored in the pipe
Definition at line 1359 of file stk_sync_pipe.h.
|
private |
condition variable signaled when the pipe is no longer empty
Definition at line 1360 of file stk_sync_pipe.h.
|
private |
condition variable signaled when the pipe is no longer full
Definition at line 1361 of file stk_sync_pipe.h.
|
private |
index of the next slot to be written (producer)
Definition at line 1357 of file stk_sync_pipe.h.
|
private |
index of the next slot to be read (consumer)
Definition at line 1358 of file stk_sync_pipe.h.