Condy v1.6.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
condy::legacy::Channel< T, N > Class Template Reference

[Deprecated] Thread-safe bounded channel for communication and synchronization. More...

#include <channel_legacy.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>
bool try_push (U &&item)
 Try to push an item into the channel.
std::optional< 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.

Detailed Description

template<typename T, size_t N = 2>
class condy::legacy::Channel< T, N >

[Deprecated] Thread-safe bounded channel for communication and synchronization.

Template Parameters
TType of the items transmitted through the channel.
NWhen 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.

Deprecated
This class is deprecated. Please use condy::Channel instead, which has a more consistent error handling strategy.

Definition at line 46 of file channel_legacy.hpp.

Constructor & Destructor Documentation

◆ Channel()

template<typename T, size_t N = 2>
condy::legacy::Channel< T, N >::Channel ( size_t capacity)
inline

Construct a new Channel object.

Parameters
capacityCapacity of the channel. If capacity is zero, the channel operates in unbuffered mode.

Definition at line 53 of file channel_legacy.hpp.

Member Function Documentation

◆ empty()

template<typename T, size_t N = 2>
bool condy::legacy::Channel< T, N >::empty ( ) const
inlinenoexcept

Check if the channel is empty.

Warning
This function may not be accurate in multithreaded scenarios.

Definition at line 159 of file channel_legacy.hpp.

◆ is_closed()

template<typename T, size_t N = 2>
bool condy::legacy::Channel< T, N >::is_closed ( ) const
inlinenoexcept

Check if the channel is closed.

Warning
This function may not be accurate in multithreaded scenarios.

Definition at line 168 of file channel_legacy.hpp.

◆ pop()

template<typename T, size_t N = 2>
PopAwaiter condy::legacy::Channel< T, N >::pop ( )
inlinenoexcept

Pop an item from the channel, awaiting if necessary.

Returns
PopAwaiter Awaiter object for the pop operation.

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 139 of file channel_legacy.hpp.

◆ push()

template<typename T, size_t N = 2>
PushAwaiter condy::legacy::Channel< T, N >::push ( T item)
inlinenoexcept

Push an item into the channel, awaiting if necessary.

Parameters
itemThe item to be pushed into the channel.
Returns
PushAwaiter Awaiter object for the push operation.

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.

Warning
The item will be moved during the push operation. If the push operation is cancelled, the moved item will be destroyed immediately and will not be pushed into the channel.

Definition at line 128 of file channel_legacy.hpp.

◆ push_close()

template<typename T, size_t N = 2>
void condy::legacy::Channel< T, N >::push_close ( )
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 pop operations will return default-constructed T values. All pending push operations will throw std::logic_error.

Note
This function is idempotent.

Definition at line 181 of file channel_legacy.hpp.

◆ size()

template<typename T, size_t N = 2>
size_t condy::legacy::Channel< T, N >::size ( ) const
inlinenoexcept

Get the current size of the channel.

Warning
This function may not be accurate in multithreaded scenarios.

Definition at line 150 of file channel_legacy.hpp.

◆ try_pop()

template<typename T, size_t N = 2>
std::optional< T > condy::legacy::Channel< T, N >::try_pop ( )
inlinenoexcept

Try to pop an item from the channel.

Returns
std::optional<T> The popped item if successful; A default-constructed T if the channel is closed; std::nullopt if the channel is empty.

Definition at line 89 of file channel_legacy.hpp.

◆ try_push()

template<typename T, size_t N = 2>
template<typename U>
requires std::is_same_v<std::decay_t<U>, T>
bool condy::legacy::Channel< T, N >::try_push ( U && item)
inline

Try to push an item into the channel.

Parameters
itemThe item to be pushed into the channel.
Returns
bool True if the item was successfully pushed.
Exceptions
std::logic_errorIf the channel is closed.

Definition at line 75 of file channel_legacy.hpp.


The documentation for this class was generated from the following file: