Go to the documentation of this file.
38 #ifndef __BASE_COROUTINE_HH__
39 #define __BASE_COROUTINE_HH__
61 template <
typename Arg,
typename Ret>
70 std::is_same<Arg, void>::value,
Empty, std::stack<Arg>>
::type;
73 std::is_same<Ret, void>::value,
Empty, std::stack<Ret>>
::type;
99 template <
typename T = Ret>
102 !std::is_same<T, void>::value, T> param)
117 template <
typename T = Ret>
118 typename std::enable_if_t<std::is_same<T, void>::value,
138 template <
typename T = Arg>
139 typename std::enable_if_t<!std::is_same<T, void>::value, T>
143 while (args_channel.empty()) {
147 auto ret = args_channel.top();
209 template <
typename T = Arg>
212 !std::is_same<T, void>::value, T> param)
227 template <
typename T = Arg>
228 typename std::enable_if_t<std::is_same<T, void>::value,
Coroutine> &
247 template <
typename T = Ret>
248 typename std::enable_if_t<!std::is_same<T, void>::value, T>
252 while (ret_channel.empty()) {
256 auto ret = ret_channel.top();
266 operator bool()
const {
return !this->
finished(); }
297 #endif // __BASE_COROUTINE_HH__
std::function< void(CallerType &)> task
Coroutine task.
ArgChannel argsChannel
Arguments for the coroutine.
CallerType: A reference to an object of this class will be passed to the coroutine task.
CallerType & operator()(typename std::enable_if_t< !std::is_same< T, void >::value, T > param)
operator() is the way we can jump outside the coroutine and return a value to the caller.
std::enable_if_t< std::is_same< T, void >::value, CallerType > & operator()()
operator() is the way we can jump outside the coroutine
bool finished() const
Returns whether the "main" function of this fiber has finished.
typename std::conditional< std::is_same< Arg, void >::value, Empty, std::stack< Arg > >::type ArgChannel
This class represents a fiber, which is a light weight sort of thread which is cooperatively schedule...
static Fiber * currentFiber()
Get a pointer to the current running Fiber.
Coroutine & operator=(const Coroutine &rhs)=delete
void run()
Start executing the fiber represented by this object.
This template defines a Coroutine wrapper type with a Boost-like interface.
typename std::conditional< std::is_same< Ret, void >::value, Empty, std::stack< Ret > >::type RetChannel
Coroutine & operator()(typename std::enable_if_t< !std::is_same< T, void >::value, T > param)
Coroutine interface.
CallerType(Coroutine &_coro)
std::enable_if_t<!std::is_same< T, void >::value, T > get()
get() is the way we can extrapolate arguments from the coroutine caller.
void main() override
Overriding base (Fiber) main.
CallerType caller
Coroutine caller.
std::enable_if_t<!std::is_same< T, void >::value, T > get()
get() is the way we can extrapolate return values (yielded) from the coroutine.
std::enable_if_t< std::is_same< T, void >::value, Coroutine > & operator()()
operator() is the way we can jump inside the coroutine.
Coroutine(std::function< void(CallerType &)> f, bool run_coroutine=true)
Coroutine constructor.
Generated on Tue Mar 23 2021 19:41:23 for gem5 by doxygen 1.8.17