|
Condy v1.6.0
C++ Asynchronous System Call Layer for Linux
|
Thread-safe bounded channel for communication and synchronization. More...
#include <channel.hpp>
Classes | |
| struct | PushAwaiter |
| Awaiter for pushing an item into the channel. More... | |
| struct | PopAwaiter |
| Awaiter for popping an item from the channel. More... | |
Public Member Functions | |
| Channel (size_t capacity) | |
| Construct a new Channel object. | |
| template<typename U> requires std::is_same_v<std::decay_t<U>, T> | |
| int | try_push (U &&item) noexcept |
| Try to push an item into the channel. | |
| std::pair< int, T > | try_pop () noexcept |
| Try to pop an item from the channel. | |
| PushAwaiter | push (T item) noexcept |
| Push an item into the channel, awaiting if necessary. | |
| PopAwaiter | 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 40 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 47 of file channel.hpp.
|
inlinenoexcept |
Check if the channel is empty.
Definition at line 165 of file channel.hpp.
|
inlinenoexcept |
Check if the channel is closed.
Definition at line 174 of file channel.hpp.
|
inlinenoexcept |
Pop an item from the channel, awaiting if necessary.
This function attempts to pop an item from the channel. If the channel is empty, the coroutine will be suspended until an item becomes available. If the channel is closed, the pop operation will return -EPIPE. If this operation is cancelled while waiting, it will return -ECANCELED.
Definition at line 145 of file channel.hpp.
|
inlinenoexcept |
Push an item into the channel, awaiting if necessary.
| item | The item to be pushed into the channel. |
This function attempts to push the given item into the channel. If the channel is full, the coroutine will be suspended until space becomes available. If the channel is closed, the push operation will return -EPIPE. If this operation is cancelled while waiting, it will return -ECANCELED.
Definition at line 133 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 187 of file channel.hpp.
|
inlinenoexcept |
Get the current size of the channel.
Definition at line 156 of file channel.hpp.
|
inlinenoexcept |
Try to pop an item from the channel.
Definition at line 86 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 69 of file channel.hpp.