38#ifndef __BASE_COROUTINE_HH__
39#define __BASE_COROUTINE_HH__
62template <
typename Arg,
typename Ret>
71 std::is_same_v<Arg, void>,
Empty, std::stack<Arg>>;
74 std::is_same_v<Ret, void>,
Empty, std::stack<Ret>>;
100 template <
typename T = Ret>
103 !std::is_same_v<T, void>, T> param)
118 template <
typename T = Ret>
119 typename std::enable_if_t<std::is_same_v<T, void>,
139 template <
typename T = Arg>
140 typename std::enable_if_t<!std::is_same_v<T, void>, T>
143 auto& args_channel =
coro.argsChannel;
144 while (args_channel.empty()) {
148 auto ret = args_channel.top();
185 Coroutine(std::function<
void(CallerType&)>
f,
bool run_coroutine =
true)
210 template <
typename T = Arg>
212 operator()(
typename std::enable_if_t<!std::is_same_v<T, void>, T> param)
227 template <
typename T = Arg>
228 typename std::enable_if_t<std::is_same_v<T, void>,
Coroutine> &
247 template <
typename T = Ret>
248 typename std::enable_if_t<!std::is_same_v<T, void>, T>
251 auto& ret_channel =
caller.retChannel;
252 while (ret_channel.empty()) {
256 auto ret = ret_channel.top();
266 operator bool()
const {
return !this->
finished(); }
289 std::function<void(CallerType&)>
task;
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
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
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 & operator=(const Coroutine &rhs)=delete
std::enable_if_t< std::is_same_v< T, void >, CallerType > & operator()()
operator() is the way we can jump outside 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.
std::enable_if_t<!std::is_same_v< T, void >, T > get()
get() is the way we can extrapolate arguments from the coroutine 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 >, Coroutine > & operator()()
operator() is the way we can jump inside 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.
Fiber(size_t stack_size=DefaultStackSize)
void run()
Start executing the fiber represented by this object.
Copyright (c) 2024 Arm Limited All rights reserved.