40 #ifndef __BASE_COROUTINE_HH__ 41 #define __BASE_COROUTINE_HH__ 63 template <
typename Arg,
typename Ret>
72 std::is_same<Arg, void>::value,
Empty, std::stack<Arg>>
::type;
75 std::is_same<Ret, void>::value, Empty, std::stack<Ret>>
::type;
99 template <
typename T = Ret>
102 !std::is_same<T, void>::value, T>::
type param)
104 retChannel.push(param);
115 template <
typename T = Ret>
116 typename std::enable_if<std::is_same<T, void>::value,
134 template <
typename T = Arg>
135 typename std::enable_if<!std::is_same<T, void>::value, T>::type
138 auto& args_channel = coro.argsChannel;
139 while (args_channel.empty()) {
143 auto ret = args_channel.top();
193 template <
typename T = Arg>
196 !std::is_same<T, void>::value, T>::
type param)
209 template <
typename T = Arg>
210 typename std::enable_if<std::is_same<T, void>::value,
Coroutine>::type&
227 template <
typename T = Ret>
228 typename std::enable_if<!std::is_same<T, void>::value, T>::type
232 while (ret_channel.empty()) {
236 auto ret = ret_channel.top();
242 operator bool()
const {
return !this->
finished(); }
265 std::function<void(CallerType&)>
task;
273 #endif // __BASE_COROUTINE_HH__ void run()
Start executing the fiber represented by this object.
bool finished() const
Returns whether the "main" function of this fiber has finished.
void main() override
Overriding base (Fiber) main.
CallerType caller
Coroutine caller.
std::enable_if< std::is_same< T, void >::value, Coroutine >::type & operator()()
operator() is the way we can jump inside the coroutine.
Coroutine(std::function< void(CallerType &)> f, bool run_coroutine=true)
Coroutine constructor.
CallerType: A reference to an object of this class will be passed to the coroutine task...
Coroutine & operator()(typename std::enable_if< !std::is_same< T, void >::value, T >::type param)
Coroutine interface.
CallerType & operator()(typename std::enable_if< !std::is_same< T, void >::value, T >::type param)
operator() is the way we can jump outside the coroutine and return a value to the caller...
This template defines a Coroutine wrapper type with a Boost-like interface.
std::enable_if< std::is_same< T, void >::value, CallerType >::type & operator()()
operator() is the way we can jump outside the coroutine
Coroutine & operator=(const Coroutine &rhs)=delete
CallerType(Coroutine &_coro)
std::function< void(CallerType &)> task
Coroutine task.
This class represents a fiber, which is a light weight sort of thread which is cooperatively schedule...
ArgChannel argsChannel
Arguments for the coroutine.
static Fiber * currentFiber()
Get a pointer to the current running Fiber.
typename std::conditional< std::is_same< Arg, void >::value, Empty, std::stack< Arg > >::type ArgChannel
typename std::conditional< std::is_same< Ret, void >::value, Empty, std::stack< Ret > >::type RetChannel