Nugget
|
Stackful coroutine class. More...
#include <psyqo/coroutine.hh>
Public Member Functions | |
Stackful ()=default | |
Stackful (const Stackful &)=delete | |
Stackful & | operator= (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 | |
![]() | |
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 | |
StackfulBase & | operator= (const StackfulBase &)=delete |
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.
|
default |
|
delete |
|
inline |
Initialize the coroutine with a function and an argument.
func | Function to be executed by the coroutine. |
arg | Argument to be passed to the function. |
|
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.
|
delete |
|
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".
|
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.
|
staticconstexpr |