CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Channel< T, Lockable > Class Template Referencefinal

The coroutine channel is a helper utility class that allows to implement easy object passing between coroutines. More...

#include <CeresEngine/Foundation/Channel.hpp>

Classes

class  LinkedList
 Minimal linked list without node allocation. More...
 
class  Reader
 Awaitable reader for Channel More...
 
class  Writer
 Awaitable writer for channel More...
 

Public Types

using Pointer = T *
 A pointer to T
 
using Reference = T &
 A reference of T
 
using Mutex = Lockable
 The mutex type used to lock the channel.
 

Public Member Functions

 Channel ()=default
 Create a new channel.
 
 Channel (const Channel &)=delete
 Deleted copy constructor.
 
 Channel (Channel &&)=delete
 Deleted copy assignment operator.
 
Channeloperator= (const Channel &)=delete
 Deleted move constructor.
 
Channeloperator= (Channel &&)=delete
 Deleted move assignment operator.
 
 ~Channel () noexcept
 Destroys the channel.
 
Writer write (T value) noexcept
 Writes a value to the channel.
 
Reader read () noexcept
 Reads a value from the channel.
 

Private Types

using CoroutineHandle = typename std::coroutine_handle< void >
 A type-alias to the coroutine handle used by channels.
 

Static Private Member Functions

static constexpr voidpoison () noexcept
 

Private Attributes

Mutex mutex
 The mutex that synchronizes access to the channel.
 
LinkedList< Readerreaders
 A LinkedList of Readers.
 
LinkedList< Writerwriters
 A LinkedList of Writers.
 

Detailed Description

template<typename T, typename Lockable = NullLockable>
class CeresEngine::Channel< T, Lockable >

The coroutine channel is a helper utility class that allows to implement easy object passing between coroutines.

An object written by a Writer will be received by a Reader. The Writer coroutine will resume after the `Reader“ awaits for another object.

objects to a channel

Channel<int> channel;
co_await channel.write(100);
co_await channel.write(123);
The coroutine channel is a helper utility class that allows to implement easy object passing between ...
Definition Channel.hpp:42
Writer write(T value) noexcept
Writes a value to the channel.
Definition Channel.hpp:100
Template Parameters
Tthe type of object to be passed through the channel
Lockablea lockable type used to synchronize the channel. By default this is NullLockable which does no locking. If the channel is being used across different threads, you must use a real lock like Mutex.

Member Typedef Documentation

◆ CoroutineHandle

template<typename T , typename Lockable = NullLockable>
using CeresEngine::Channel< T, Lockable >::CoroutineHandle = typename std::coroutine_handle<void>
private

A type-alias to the coroutine handle used by channels.

◆ Mutex

template<typename T , typename Lockable = NullLockable>
using CeresEngine::Channel< T, Lockable >::Mutex = Lockable

The mutex type used to lock the channel.

◆ Pointer

template<typename T , typename Lockable = NullLockable>
using CeresEngine::Channel< T, Lockable >::Pointer = T*

A pointer to T

◆ Reference

template<typename T , typename Lockable = NullLockable>
using CeresEngine::Channel< T, Lockable >::Reference = T&

A reference of T

Constructor & Destructor Documentation

◆ Channel() [1/3]

template<typename T , typename Lockable = NullLockable>
CeresEngine::Channel< T, Lockable >::Channel ( )
default

Create a new channel.

◆ Channel() [2/3]

template<typename T , typename Lockable = NullLockable>
CeresEngine::Channel< T, Lockable >::Channel ( const Channel< T, Lockable > &  )
delete

Deleted copy constructor.

◆ Channel() [3/3]

template<typename T , typename Lockable = NullLockable>
CeresEngine::Channel< T, Lockable >::Channel ( Channel< T, Lockable > &&  )
delete

Deleted copy assignment operator.

◆ ~Channel()

template<typename T , typename Lockable >
CeresEngine::Channel< T, Lockable >::~Channel ( )
noexcept

Destroys the channel.

Member Function Documentation

◆ operator=() [1/2]

template<typename T , typename Lockable = NullLockable>
Channel & CeresEngine::Channel< T, Lockable >::operator= ( Channel< T, Lockable > &&  )
delete

Deleted move assignment operator.

◆ operator=() [2/2]

template<typename T , typename Lockable = NullLockable>
Channel & CeresEngine::Channel< T, Lockable >::operator= ( const Channel< T, Lockable > &  )
delete

Deleted move constructor.

◆ poison()

template<typename T , typename Lockable = NullLockable>
static constexpr void * CeresEngine::Channel< T, Lockable >::poison ( )
inlinestaticconstexprprivatenoexcept
Returns
A poisoned pointer. Indicates the channel is being destroyed.

◆ read()

template<typename T , typename Lockable = NullLockable>
Reader CeresEngine::Channel< T, Lockable >::read ( )
inlinenoexcept

Reads a value from the channel.

Returns
An awaitable Reader object

◆ write()

template<typename T , typename Lockable = NullLockable>
Writer CeresEngine::Channel< T, Lockable >::write ( T  value)
inlinenoexcept

Writes a value to the channel.

Parameters
valueThe value to write to the channel
Returns
An awaitable Writer object

Member Data Documentation

◆ mutex

template<typename T , typename Lockable = NullLockable>
Mutex CeresEngine::Channel< T, Lockable >::mutex
private

The mutex that synchronizes access to the channel.

◆ readers

template<typename T , typename Lockable = NullLockable>
LinkedList<Reader> CeresEngine::Channel< T, Lockable >::readers
private

◆ writers

template<typename T , typename Lockable = NullLockable>
LinkedList<Writer> CeresEngine::Channel< T, Lockable >::writers
private

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