16#include <continuable/continuable.hpp>
42 template<
typename T,
typename Lockable = NullLockable>
class Channel final {
44 static_assert(std::is_reference_v<T> ==
false,
"Using reference for channel is forbidden.");
190 std::swap(
value, rhs.value);
191 std::swap(
handle, rhs.handle);
192 std::swap(
channel, rhs.channel);
199 std::swap(
value, rhs.value);
200 std::swap(
handle, rhs.handle);
201 std::swap(
channel, rhs.channel);
251 std::swap(
value, rhs.value);
252 std::swap(
handle, rhs.handle);
253 std::swap(
channel, rhs.channel);
260 std::swap(
value, rhs.value);
261 std::swap(
handle, rhs.handle);
262 std::swap(
channel, rhs.channel);
295 w->handle = std::nullopt;
320 std::swap(this->value,
w->value);
321 std::swap(this->handle,
w->handle);
331 this->
next =
nullptr;
344 T value = std::move(this->value.get());
351 return std::move(
value);
361 std::swap(this->value, r->
value);
362 std::swap(this->handle, r->
handle);
372 this->
next =
nullptr;
#define CE_UNLIKELY
Definition Macros.hpp:397
Minimal linked list without node allocation.
Definition Channel.hpp:113
NodeType * head
The head node.
Definition Channel.hpp:115
void push(NodeType *node) noexcept
Pushes a new node into the list.
Definition Channel.hpp:131
LinkedList() noexcept=default
Creates a new LinkedList.
NodeType * tail
The tail node.
Definition Channel.hpp:118
NodeType * pop() noexcept
Pops a node from the list.
Definition Channel.hpp:142
bool empty() const noexcept
Checks if the list is empty.
Definition Channel.hpp:127
Awaitable reader for Channel
Definition Channel.hpp:156
Channel * channel
The channel to push this reader.
Definition Channel.hpp:172
~Reader() noexcept=default
Destroys the reader.
Optional< T > value
The address of value.
Definition Channel.hpp:162
Reader & operator=(Reader &&rhs) noexcept
Assigns the reader by moving the contents of another.
Definition Channel.hpp:198
Reader & operator=(const Reader &)=delete
Deleted copy assignment operator.
Reader(Reader &&rhs) noexcept
Creates a new reader by moving the contents of another.
Definition Channel.hpp:189
bool await_ready() const &
Definition Channel.hpp:309
Reader(const Reader &)=delete
Deleted copy constructor.
void await_suspend(CoroutineHandle coro) &
Definition Channel.hpp:326
friend Channel
Definition Channel.hpp:158
Optional< CoroutineHandle > handle
The coroutine handle.
Definition Channel.hpp:165
Reader * next
Next reader in the queue.
Definition Channel.hpp:169
Reader(Channel &ch) noexcept
Creates a new channel reader.
Definition Channel.hpp:178
Optional< T > await_resume() &
Definition Channel.hpp:337
Awaitable writer for channel
Definition Channel.hpp:215
void await_suspend(CoroutineHandle coro) &
Definition Channel.hpp:367
bool await_resume() &
Definition Channel.hpp:378
Writer(Channel &channel, T &&value) noexcept
Creates a new writer for the given channel with the given pv value.
Definition Channel.hpp:239
Writer(const Writer &)=delete
Deleted copy constructor.
friend Channel
Definition Channel.hpp:217
bool await_ready() const &
Definition Channel.hpp:354
Writer(Writer &&rhs) noexcept
Creates a new writer by moving the contents of another.
Definition Channel.hpp:250
Optional< CoroutineHandle > handle
The coroutine handle.
Definition Channel.hpp:224
Writer & operator=(Writer &&rhs) noexcept
Assigns the writer by moving the contents of another.
Definition Channel.hpp:259
Writer & operator=(const Writer &)=delete
Deleted copy assignment operator.
~Writer() noexcept=default
Destroys the writer.
Channel * channel
The channel to push this reader.
Definition Channel.hpp:231
The coroutine channel is a helper utility class that allows to implement easy object passing between ...
Definition Channel.hpp:42
Lockable Mutex
The mutex type used to lock the channel.
Definition Channel.hpp:57
Channel(Channel &&)=delete
Deleted copy assignment operator.
Channel & operator=(const Channel &)=delete
Deleted move constructor.
Writer write(T value) noexcept
Writes a value to the channel.
Definition Channel.hpp:100
T & Reference
A reference of T
Definition Channel.hpp:54
LinkedList< Reader > readers
A LinkedList of Readers.
Definition Channel.hpp:72
Mutex mutex
The mutex that synchronizes access to the channel.
Definition Channel.hpp:67
Channel & operator=(Channel &&)=delete
Deleted move assignment operator.
~Channel() noexcept
Destroys the channel.
Definition Channel.hpp:276
typename std::coroutine_handle< void > CoroutineHandle
A type-alias to the coroutine handle used by channels.
Definition Channel.hpp:47
Reader read() noexcept
Reads a value from the channel.
Definition Channel.hpp:104
Channel(const Channel &)=delete
Deleted copy constructor.
static constexpr void * poison() noexcept
Definition Channel.hpp:109
Channel()=default
Create a new channel.
LinkedList< Writer > writers
A LinkedList of Writers.
Definition Channel.hpp:75
T * Pointer
A pointer to T
Definition Channel.hpp:51
The class Lock is a mutex wrapper that provides a convenient RAII-style mechanism for owning one or m...
Definition Threading.hpp:246
Definition Optional.hpp:17
Definition Application.hpp:19
decltype(auto) lock(Func &&func, Ts &... objects)
Definition Threading.hpp:667
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25