![]() |
SuperTinyKernel™ RTOS 1.05.3
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Thread-safe FIFO communication pipe for inter-task data passing. More...
#include <stk_sync_pipe.h>
Public Member Functions | |
| Pipe () | |
| Constructor. | |
| bool | Write (const T &data, Timeout timeout=WAIT_INFINITE) |
| Write data to the pipe. | |
| bool | TryWrite (const T &data) |
| Attempt to write data to the pipe. | |
| size_t | WriteBulk (const T *src, size_t count, Timeout timeout=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. | |
| bool | Read (T &data, Timeout timeout=WAIT_INFINITE) |
| Read data from the pipe. | |
| bool | TryRead (T &data) |
| Attempt to read data from the pipe. | |
| size_t | ReadBulk (T *dst, size_t count, Timeout timeout=WAIT_INFINITE) |
| Read multiple elements from the pipe. | |
| size_t | TryReadBulk (T *dst, size_t count) |
| Attempt to read multiple elements from the pipe. | |
| size_t | GetSize () const |
| Get the current number of elements in the pipe. | |
| bool | IsEmpty () const |
| Check if queue is currently empty. | |
Private Member Functions | |
| STK_NONCOPYABLE_CLASS (Pipe) | |
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_empty |
| condition variable signaled when the pipe is no longer empty | |
| ConditionVariable | m_cv_full |
| condition variable signaled when the pipe is no longer full | |
Thread-safe FIFO communication pipe for inter-task data passing.
| T | Data type of elements. |
| N | Capacity of the pipe (number of elements). |
Pipe provides a synchronized ring-buffer mechanism that allows tasks to exchange 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.Definition at line 58 of file stk_sync_pipe.h.
|
inlineexplicit |
Constructor.
Definition at line 63 of file stk_sync_pipe.h.
|
inline |
Get the current number of elements in the pipe.
Definition at line 337 of file stk_sync_pipe.h.
Referenced by stk::sync::Pipe< Timer *, 32 >::IsEmpty(), and stk_pipe_get_size().
|
inline |
Check if queue is currently empty.
Definition at line 346 of file stk_sync_pipe.h.
|
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 | 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 207 of file stk_sync_pipe.h.
Referenced by stk_pipe_read(), and stk::sync::Pipe< Timer *, 32 >::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 | Maximum time to wait for data (ticks). Default: WAIT_INFINITE. |
count unless a timeout occurred. Definition at line 260 of file stk_sync_pipe.h.
Referenced by stk_pipe_read_bulk(), and stk::sync::Pipe< Timer *, 32 >::TryReadBulk().
|
private |
|
inline |
Attempt to read data from the pipe.
Checks if an element is available in the FIFO and retrieves it immediately without blocking. If the pipe is empty, returns false without yielding the CPU or touching the kernel wait list.
| [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 235 of file stk_sync_pipe.h.
|
inline |
Attempt to read multiple elements from the pipe.
Reads as many elements as are currently available in the FIFO without blocking. If fewer elements than requested are available, only the available elements are read.
| [out] | dst | Pointer to the destination array. |
| [in] | count | Number of elements to read. |
count if all requested elements were available, or less if the pipe was empty or became empty before all elements could be read. Definition at line 328 of file stk_sync_pipe.h.
|
inline |
Attempt to write data to the pipe.
Attempts to push an element into the FIFO queue. If pipe is full, a false will be returned without waiting for a free space.
| [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 103 of file stk_sync_pipe.h.
|
inline |
Attempt to write multiple elements to the pipe.
Copies as many elements as possible into the FIFO without blocking. If the pipe does not have enough space for the entire block, only the elements that fit are written and the rest are discarded.
| [in] | src | Pointer to the source array. |
| [in] | count | Number of elements to write. |
count if all elements were written successfully, or less if the pipe was full or became full before all elements could be written. Definition at line 195 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 | 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 76 of file stk_sync_pipe.h.
Referenced by stk_pipe_write(), and stk::sync::Pipe< Timer *, 32 >::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 | Maximum time to wait for sufficient space (ticks). |
count unless a timeout occurred. Definition at line 127 of file stk_sync_pipe.h.
Referenced by stk_pipe_write_bulk(), and stk::sync::Pipe< Timer *, 32 >::TryWriteBulk().
|
private |
static storage for FIFO elements
Definition at line 351 of file stk_sync_pipe.h.
|
private |
current number of elements stored in the pipe
Definition at line 354 of file stk_sync_pipe.h.
|
private |
condition variable signaled when the pipe is no longer empty
Definition at line 355 of file stk_sync_pipe.h.
|
private |
condition variable signaled when the pipe is no longer full
Definition at line 356 of file stk_sync_pipe.h.
|
private |
index of the next slot to be written (producer)
Definition at line 352 of file stk_sync_pipe.h.
|
private |
index of the next slot to be read (consumer)
Definition at line 353 of file stk_sync_pipe.h.