10#ifndef STK_SYNC_PIPE_H_
11#define STK_SYNC_PIPE_H_
57template <
typename T,
size_t N>
129 if ((src ==
nullptr) || (count == 0U))
135 while (written < count)
145 size_t available = N -
m_count;
146 size_t to_write = ((count - written) < available ? (count - written) : available);
151 if (!std::is_scalar<T>::value && (N < 8))
153 for (
size_t i = 0; i < to_write; ++i)
162 size_t first_part = N -
m_head;
163 if (to_write <= first_part)
169 memcpy(&
m_buffer[
m_head], &src[written], (first_part *
sizeof(T)));
170 memcpy(&
m_buffer[0], &src[written + first_part], ((to_write - first_part) *
sizeof(T)));
262 if ((dst ==
nullptr) || (count == 0U))
265 size_t read_count = 0U;
269 while (read_count < count)
279 size_t to_read = (count - read_count) <
m_count ? (count - read_count) :
m_count;
284 if (!std::is_scalar<T>::value || (N < 8))
286 for (
size_t i = 0U; i < to_read; ++i)
295 size_t first_part = N -
m_tail;
296 if (to_read <= first_part)
298 memcpy(&dst[read_count], &
m_buffer[
m_tail], (to_read *
sizeof(T)));
302 memcpy(&dst[read_count], &
m_buffer[
m_tail], (first_part *
sizeof(T)));
303 memcpy(&dst[read_count + first_part], &
m_buffer[0], ((to_read - first_part) *
sizeof(T)));
305 read_count += to_read;
Implementation of synchronization primitive: stk::sync::ConditionVariable.
Namespace of STK package.
const Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
int32_t Timeout
Timeout time (ticks).
const Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Synchronization primitives for task coordination and resource protection.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Condition Variable primitive for signaling between tasks based on specific predicates.
bool TryRead(T &data)
Attempt to read data from the pipe.
ConditionVariable m_cv_full
ConditionVariable m_cv_empty
size_t GetSize() const
Get the current number of elements in 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 Write(const T &data, Timeout timeout=WAIT_INFINITE)
Write data to the pipe.
bool Read(T &data, Timeout timeout=WAIT_INFINITE)
Read data from the pipe.
bool IsEmpty() const
Check if queue is currently empty.
bool TryWrite(const T &data)
Attempt to write data to the pipe.
STK_NONCOPYABLE_CLASS(Pipe)
size_t TryReadBulk(T *dst, size_t count)
Attempt to read multiple elements from the pipe.
size_t ReadBulk(T *dst, size_t count, Timeout timeout=WAIT_INFINITE)
Read multiple elements from the pipe.