|
Condy v1.3.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> | |
| bool | try_push (U &&item) |
| Try to push an item into the channel. | |
| std::optional< T > | try_pop () |
| Try to pop an item from the channel. | |
| template<typename U> | |
| PushAwaiter | push (U &&item) |
| Push an item into the channel, awaiting if necessary. | |
| PopAwaiter | pop () |
| 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 () |
| 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 33 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 40 of file channel.hpp.
|
inlinenoexcept |
Check if the channel is empty.
Definition at line 134 of file channel.hpp.
|
inlinenoexcept |
Check if the channel is closed.
Definition at line 143 of file channel.hpp.
|
inline |
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, a default-constructed T will be returned.
Definition at line 114 of file channel.hpp.
|
inline |
Push an item into the channel, awaiting if necessary.
| U | Type of the item to be pushed. |
| 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, a std::logic_error will be thrown.
Definition at line 101 of file channel.hpp.
|
inline |
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 pop operations will return default-constructed T values. All pending push operations will throw std::logic_error.
Definition at line 156 of file channel.hpp.
|
inlinenoexcept |
Get the current size of the channel.
Definition at line 125 of file channel.hpp.
|
inline |
Try to pop an item from the channel.
Definition at line 72 of file channel.hpp.
|
inline |
Try to push an item into the channel.
| U | Type of the item to be pushed. |
| item | The item to be pushed into the channel. |
| std::logic_error | If the channel is closed. |
Definition at line 62 of file channel.hpp.