Nugget
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | List of all members
psyqo::Stackful< StackSize > Class Template Reference

Stackful coroutine class. More...

#include <psyqo/coroutine.hh>

Inheritance diagram for psyqo::Stackful< StackSize >:
Inheritance graph
[legend]
Collaboration diagram for psyqo::Stackful< StackSize >:
Collaboration graph
[legend]

Public Member Functions

 Stackful ()=default
 
 Stackful (const Stackful &)=delete
 
Stackfuloperator= (const Stackful &)=delete
 
void initialize (eastl::function< void()> &&func)
 Initialize the coroutine with a function and an argument.
 
void resume ()
 Resume the coroutine.
 
void yield ()
 Yield the coroutine.
 
bool isAlive () const
 Check if the coroutine is currently alive.
 

Static Public Attributes

static constexpr unsigned c_stackSize = (StackSize + 7) & ~7
 

Additional Inherited Members

- Protected Member Functions inherited from psyqo::StackfulBase
void initializeInternal (eastl::function< void()> &&func, void *ss_sp, unsigned ss_size)
 
void resume ()
 
void yield ()
 
bool isAlive () const
 
 StackfulBase ()=default
 
 StackfulBase (const StackfulBase &)=delete
 
StackfulBaseoperator= (const StackfulBase &)=delete
 

Detailed Description

template<unsigned StackSize = 0x10000>
class psyqo::Stackful< StackSize >

Stackful coroutine class.

This class provides a simple stackful coroutine implementation. It allows you to create coroutines that can yield and resume execution. While the Coroutine class above is a C++20 coroutine, it requires that all of the code being run are coroutines or awaitables all the way down. This class is a more traditional coroutine implementation that uses a separate stack for each coroutine, allowing it to yield and resume execution without requiring the entire call stack to be coroutine-aware. It is suitable for use in scenarios where you need to yield execution from legacy code without converting it to C++20 coroutines.

Constructor & Destructor Documentation

◆ Stackful() [1/2]

template<unsigned StackSize = 0x10000>
psyqo::Stackful< StackSize >::Stackful ( )
default

◆ Stackful() [2/2]

template<unsigned StackSize = 0x10000>
psyqo::Stackful< StackSize >::Stackful ( const Stackful< StackSize > &  )
delete

Member Function Documentation

◆ initialize()

template<unsigned StackSize = 0x10000>
void psyqo::Stackful< StackSize >::initialize ( eastl::function< void()> &&  func)
inline

Initialize the coroutine with a function and an argument.

Parameters
funcFunction to be executed by the coroutine.
argArgument to be passed to the function.

◆ isAlive()

template<unsigned StackSize = 0x10000>
bool psyqo::Stackful< StackSize >::isAlive ( ) const
inline

Check if the coroutine is currently alive.

A coroutine is considered alive if it has been initialized and has not yet completed its execution. It becomes not alive when it returns from its function.

Returns
true if the coroutine is alive, false otherwise.

◆ operator=()

template<unsigned StackSize = 0x10000>
Stackful & psyqo::Stackful< StackSize >::operator= ( const Stackful< StackSize > &  )
delete

◆ resume()

template<unsigned StackSize = 0x10000>
void psyqo::Stackful< StackSize >::resume ( )
inline

Resume the coroutine.

This will switch to the coroutine's context and execute it. If the coroutine is not alive, this function does nothing. This function should be called after the coroutine has been initialized, and it will return to the point where the coroutine was last yielded. It can only be called from the "main thread".

◆ yield()

template<unsigned StackSize = 0x10000>
void psyqo::Stackful< StackSize >::yield ( )
inline

Yield the coroutine.

This will switch back to the main thread and save the coroutine's context. The coroutine can be resumed later using resume(). It can only be called from within the coroutine to yield execution.

Member Data Documentation

◆ c_stackSize

template<unsigned StackSize = 0x10000>
constexpr unsigned psyqo::Stackful< StackSize >::c_stackSize = (StackSize + 7) & ~7
staticconstexpr

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