Class channel

template <typename T, typename M>

Class List > channel

C++ Coroutines based channel. More...

  • #include <channel.hpp>

Inherits the following classes: internal::list, internal::list

Public Types

Type Name
typedef M mutex_type
typedef value_type * pointer
typedef value_type & reference
typedef T value_type

Public Functions

Type Name
channel () noexcept
initialized 2 linked list and given mutex
decltype(auto) read () noexcept
construct a new reader which references this channel
decltype(auto) write (reference ref) noexcept
construct a new writer which references this channel
~channel () noexcept
Resume all attached coroutine read/write operations.

Public Functions inherited from internal::list

See internal::list

Type Name
bool is_empty () noexcept const
auto pop () noexcept
void push (T * node) noexcept

Public Functions inherited from internal::list

See internal::list

Type Name
bool is_empty () noexcept const
auto pop () noexcept
void push (T * node) noexcept

Detailed Description

Note:

It works as synchronizer of channel_writer/channel_reader. The parameter mutex must meet the requirement of the synchronization.

Template parameters:

  • T type of the element
  • M Type of the mutex(lockable) for its member

Public Types Documentation

typedef mutex_type

using channel< T, M >::mutex_type =  M;

typedef pointer

using channel< T, M >::pointer =  value_type*;

typedef reference

using channel< T, M >::reference =  value_type&;

typedef value_type

using channel< T, M >::value_type =  T;

Public Functions Documentation

function channel [3/3]

inline channel::channel () noexcept

function read

inline decltype(auto) channel::read () noexcept

Returns:

channel_reader

function write

inline decltype(auto) channel::write (
    reference ref
) noexcept

Parameters:

  • ref T& which holds a value to be moved to reader.

Returns:

channel_writer

function ~channel

inline channel::~channel () noexcept

Note:

Channel can't provide exception guarantee since the destruction contains coroutines' resume

If the channel is raced hardly, some coroutines can be enqueued into list just after this destructor unlocks mutex.

Unfortunately, this can't be detected at once since we have 2 list (readers/writers) in the channel.

Current implementation allows checking repeatedly to reduce the probability of such interleaving. Modify the repeat count in the code if the situation occurs.


The documentation for this class was generated from the following file interface/coroutine/channel.hpp