gem5
v22.0.0.0
|
This template defines a Coroutine wrapper type with a Boost-like interface. More...
#include <coroutine.hh>
Classes | |
class | CallerType |
CallerType: A reference to an object of this class will be passed to the coroutine task. More... | |
struct | Empty |
Public Member Functions | |
Coroutine (std::function< void(CallerType &)> f, bool run_coroutine=true) | |
Coroutine constructor. More... | |
virtual | ~Coroutine () |
template<typename T = Arg> | |
Coroutine & | operator() (typename std::enable_if_t<!std::is_same_v< T, void >, T > param) |
Coroutine interface. More... | |
template<typename T = Arg> | |
std::enable_if_t< std::is_same_v< T, void >, Coroutine > & | operator() () |
operator() is the way we can jump inside the coroutine. More... | |
template<typename T = Ret> | |
std::enable_if_t<!std::is_same_v< T, void >, T > | get () |
get() is the way we can extrapolate return values (yielded) from the coroutine. More... | |
operator bool () const | |
Check if coroutine is still running. More... | |
Coroutine ()=delete | |
Coroutine (const Coroutine &rhs)=delete | |
Coroutine & | operator= (const Coroutine &rhs)=delete |
![]() | |
virtual | ~Fiber () |
void | run () |
Start executing the fiber represented by this object. More... | |
bool | finished () const |
Returns whether the "main" function of this fiber has finished. More... | |
bool | started () const |
Returns whether the "main" function of this fiber has started. More... | |
Fiber (size_t stack_size=DefaultStackSize) | |
Fiber (Fiber *link, size_t stack_size=DefaultStackSize) | |
Private Types | |
using | ArgChannel = typename std::conditional_t< std::is_same_v< Arg, void >, Empty, std::stack< Arg > > |
using | RetChannel = typename std::conditional_t< std::is_same_v< Ret, void >, Empty, std::stack< Ret > > |
Private Member Functions | |
void | main () override |
Overriding base (Fiber) main. More... | |
void | call () |
Private Attributes | |
ArgChannel | argsChannel |
Arguments for the coroutine. More... | |
std::function< void(CallerType &)> | task |
Coroutine task. More... | |
CallerType | caller |
Coroutine caller. More... | |
Additional Inherited Members | |
![]() | |
static Fiber * | currentFiber () |
Get a pointer to the current running Fiber. More... | |
static Fiber * | primaryFiber () |
Get a pointer to the primary Fiber. More... | |
![]() | |
const static size_t | DefaultStackSize = 0x50000 |
![]() | |
void | setStarted () |
This template defines a Coroutine wrapper type with a Boost-like interface.
It is built on top of the gem5 fiber class. The two template parameters (Arg and Ret) are the coroutine argument and coroutine return types which are passed between the coroutine and the caller via operator() and get() method. This implementation doesn't support passing multiple values, so a tuple must be used in that scenario.
Most methods are templatized since it is relevant to distinguish the cases where one or both of the template parameters are void
Definition at line 64 of file coroutine.hh.
|
private |
Definition at line 72 of file coroutine.hh.
|
private |
Definition at line 75 of file coroutine.hh.
|
inlineprivate |
Definition at line 279 of file coroutine.hh.
References gem5::Coroutine< Arg, Ret >::caller, gem5::Coroutine< Arg, Ret >::CallerType::callerFiber, gem5::Fiber::currentFiber(), and gem5::Fiber::run().
Referenced by gem5::Coroutine< Arg, Ret >::Coroutine(), gem5::Coroutine< Arg, Ret >::get(), and gem5::Coroutine< Arg, Ret >::operator()().
|
inlineoverrideprivatevirtual |
Overriding base (Fiber) main.
This method will be automatically called by the Fiber running engine and it is a simple wrapper for the task that the coroutine is supposed to run.
Implements gem5::Fiber.
Definition at line 276 of file coroutine.hh.
References gem5::Coroutine< Arg, Ret >::caller, and gem5::Coroutine< Arg, Ret >::task.
|
private |
Arguments for the coroutine.
Definition at line 287 of file coroutine.hh.
Referenced by gem5::Coroutine< Arg, Ret >::CallerType::get(), and gem5::Coroutine< Arg, Ret >::operator()().
|
private |
Coroutine caller.
Definition at line 293 of file coroutine.hh.
Referenced by gem5::Coroutine< Arg, Ret >::call(), gem5::Coroutine< Arg, Ret >::get(), and gem5::Coroutine< Arg, Ret >::main().
|
private |
Coroutine task.
Definition at line 290 of file coroutine.hh.
Referenced by gem5::Coroutine< Arg, Ret >::main().