38 #ifndef __BASE_COROUTINE_HH__
39 #define __BASE_COROUTINE_HH__
63 template <
typename Arg,
typename Ret>
72 std::is_same_v<Arg, void>,
Empty, std::stack<Arg>>;
75 std::is_same_v<Ret, void>,
Empty, std::stack<Ret>>;
101 template <
typename T = Ret>
104 !std::is_same_v<T, void>, T> param)
119 template <
typename T = Ret>
120 typename std::enable_if_t<std::is_same_v<T, void>,
140 template <
typename T = Arg>
141 typename std::enable_if_t<!std::is_same_v<T, void>, T>
145 while (args_channel.empty()) {
149 auto ret = args_channel.top();
211 template <
typename T = Arg>
213 operator()(
typename std::enable_if_t<!std::is_same_v<T, void>, T> param)
228 template <
typename T = Arg>
229 typename std::enable_if_t<std::is_same_v<T, void>,
Coroutine> &
248 template <
typename T = Ret>
249 typename std::enable_if_t<!std::is_same_v<T, void>, T>
253 while (ret_channel.empty()) {
257 auto ret = ret_channel.top();
267 operator bool()
const {
return !this->
finished(); }
CallerType: A reference to an object of this class will be passed to the coroutine task.
CallerType(Coroutine &_coro)
This template defines a Coroutine wrapper type with a Boost-like interface.
void main() override
Overriding base (Fiber) main.
std::function< void(CallerType &)> task
Coroutine task.
CallerType caller
Coroutine caller.
typename std::conditional_t< std::is_same_v< Ret, void >, Empty, std::stack< Ret > > RetChannel
typename std::conditional_t< std::is_same_v< Arg, void >, Empty, std::stack< Arg > > ArgChannel
ArgChannel argsChannel
Arguments for the coroutine.
This class represents a fiber, which is a light weight sort of thread which is cooperatively schedule...
GEM5_DEPRECATED_NAMESPACE(m5, gem5)
std::enable_if_t< std::is_same_v< T, void >, Coroutine > & operator()()
operator() is the way we can jump inside the coroutine.
CallerType & operator()(typename std::enable_if_t< !std::is_same_v< T, void >, T > param)
operator() is the way we can jump outside the coroutine and return a value to the caller.
Coroutine & operator()(typename std::enable_if_t<!std::is_same_v< T, void >, T > param)
Coroutine interface.
std::enable_if_t<!std::is_same_v< T, void >, T > get()
get() is the way we can extrapolate arguments from the coroutine caller.
std::enable_if_t< std::is_same_v< T, void >, CallerType > & operator()()
operator() is the way we can jump outside the coroutine
Coroutine & operator=(const Coroutine &rhs)=delete
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.
Coroutine(const Coroutine &rhs)=delete
Coroutine(std::function< void(CallerType &)> f, bool run_coroutine=true)
Coroutine constructor.
static Fiber * currentFiber()
Get a pointer to the current running Fiber.
bool finished() const
Returns whether the "main" function of this fiber has finished.
void run()
Start executing the fiber represented by this object.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....