Last active
December 15, 2015 09:19
-
-
Save eahydra/5237652 to your computer and use it in GitHub Desktop.
自己实现的基于FSM的coroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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