Skip to content

Instantly share code, notes, and snippets.

@eahydra
Last active December 15, 2015 09:19
Show Gist options
  • Save eahydra/5237652 to your computer and use it in GitHub Desktop.
Save eahydra/5237652 to your computer and use it in GitHub Desktop.
自己实现的基于FSM的coroutine
#define begin() \
static unsigned int state_ = 0;\
switch (state_) \
case 0:
#define _yield_impl(x_, z_) \
do { \
state_ = z_; \
##x_; \
goto exit__;\
case z_:;\
} while (false)
#define _yield(y_) \
_yield_impl(y_, __COUNTER__ +1)
#define end() \
default:\
exit__:\
break
void coroutine_executor_yy() {
begin() {
_yield(task_thread_pool_.post_task([&](){
std::cout<<"yy ******yield***** 1"<<std::endl;
coroutine_executor_yy();
}));
_yield(task_thread_pool_.post_task([&](){
std::cout<<"yy ****yield**** 2"<<std::endl;
coroutine_executor_yy();
}));
end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment