|
Condy v1.9
C++ Asynchronous System Call Layer for Linux
|
Thread-safe bounded channel for communication and synchronization. More...
#include <channel.hpp>
Public Member Functions | |
| Channel (size_t capacity) | |
| Construct a new Channel object. | |
| template<typename U> requires std::is_same_v<std::remove_cvref_t<U>, T> | |
| int32_t | try_push (U &&item) noexcept |
| Try to push an item into the channel. | |
| std::pair< int32_t, T > | try_pop () noexcept |
| Try to pop an item from the channel. | |
| MovePushSender | push (T &&item) noexcept |
| Push an item into the channel, awaiting if necessary. | |
| CopyPushSender | push (const T &item) noexcept |
| Push an item into the channel, awaiting if necessary. | |
| PopSender | pop () noexcept |
| Pop an item from the channel, awaiting if necessary. | |
| size_t | capacity () const noexcept |
| Get the capacity of the channel. | |
| size_t | size () const noexcept |
| Get the current size of the channel. | |
| bool | empty () const noexcept |
| Check if the channel is empty. | |
| bool | is_closed () const noexcept |
| Check if the channel is closed. | |
| void | push_close () noexcept |
| Close the channel. | |
Thread-safe bounded channel for communication and synchronization.
| T | Type of the items transmitted through the channel. |
| N | When the capacity is less than or equal to N, the channel uses stack storage for buffering; otherwise, it uses heap storage. |
This class provides a thread-safe channel for communication and synchronization for both intra-Runtime and inter-Runtime scenarios. It supports both buffered and unbuffered modes, as well as push and pop operations that can be awaited in coroutines. The internal implementation utilizes msg_ring operations of io_uring for efficient cross-runtime notifications.
Definition at line 42 of file channel.hpp.
|
inline |
Construct a new Channel object.
| capacity | Capacity of the channel. If capacity is zero, the channel operates in unbuffered mode. |
Definition at line 49 of file channel.hpp.
|
inlinenoexcept |
Check if the channel is empty.
Definition at line 191 of file channel.hpp.
|
inlinenoexcept |
Check if the channel is closed.
Definition at line 200 of file channel.hpp.
|
inlinenoexcept |
Pop an item from the channel, awaiting if necessary.
Definition at line 171 of file channel.hpp.
|
inlinenoexcept |
Push an item into the channel, awaiting if necessary.
| item | The item to be pushed into the channel. |
Definition at line 154 of file channel.hpp.
|
inlinenoexcept |
Push an item into the channel, awaiting if necessary.
| item | The item to be pushed into the channel. |
Definition at line 140 of file channel.hpp.
|
inlinenoexcept |
Close the channel.
This function closes the channel. After the channel is closed, no more items can be pushed into the channel. All pending and future push operations will fail with -EPIPE. All pending pop operations will fail with -EPIPE if there are no more items to pop.
Definition at line 213 of file channel.hpp.
|
inlinenoexcept |
Get the current size of the channel.
Definition at line 182 of file channel.hpp.
|
inlinenoexcept |
Try to pop an item from the channel.
Definition at line 90 of file channel.hpp.
|
inlinenoexcept |
Try to push an item into the channel.
| item | The item to be pushed into the channel. |
Definition at line 73 of file channel.hpp.