Skip to content

Commit

Permalink
Improve coroutine state constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Nov 24, 2018
1 parent 7f88d78 commit 9ea8df1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ define co_list
end
if $co->state == 1
color $RED
printf "%s\n", "SW_CORO_YIELD"
printf "%s\n", "SW_CORO_WAITING"
color_reset
end
if $co->state == 2
Expand Down
2 changes: 1 addition & 1 deletion include/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

typedef enum
{
SW_CORO_INIT = 0, SW_CORO_YIELD, SW_CORO_RUNNING, SW_CORO_END,
SW_CORO_INIT = 0, SW_CORO_WAITING, SW_CORO_RUNNING, SW_CORO_END,
} sw_coro_state;

typedef void (*coro_php_create_t)();
Expand Down
4 changes: 2 additions & 2 deletions src/coroutine/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ long Coroutine::create(coroutine_func_t fn, void* args)

void Coroutine::yield()
{
state = SW_CORO_YIELD;
state = SW_CORO_WAITING;
if (swCoroG.onYield)
{
swCoroG.onYield(task);
Expand All @@ -80,7 +80,7 @@ void Coroutine::resume()

void Coroutine::yield_naked()
{
state = SW_CORO_YIELD;
state = SW_CORO_WAITING;
swCoroG.call_stack_size--;
ctx.SwapOut();
}
Expand Down
4 changes: 4 additions & 0 deletions swoole_coroutine_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ void swoole_coroutine_util_init(int module_number)
SWOOLE_DEFINE(DEFAULT_MAX_CORO_NUM);
SWOOLE_DEFINE(MAX_CORO_NUM_LIMIT);
SWOOLE_DEFINE(MAX_CORO_NESTING_LEVEL);
SWOOLE_DEFINE(CORO_INIT);
SWOOLE_DEFINE(CORO_WAITING);
SWOOLE_DEFINE(CORO_RUNNING);
SWOOLE_DEFINE(CORO_END);

//prohibit exit in coroutine
INIT_CLASS_ENTRY(swoole_exit_exception_ce, "Swoole\\ExitException", swoole_exit_exception_methods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ require __DIR__ . '/../../include/bootstrap.php';
co::onSwap(function (int $state, int $cid, int $origin_cid) {
$cid1 = $cid2 = -1;
switch ($state){
case 0:
case SWOOLE_CORO_INIT:
$state = 'create';
$cid1 = $origin_cid;
$cid2 = $cid;
break;
case 1:
case SWOOLE_CORO_WATING:
$state = 'yield';
$cid1 = $cid;
$cid2 = $origin_cid;
break;
case 2:
case SWOOLE_CORO_RUNNING:
$state = 'resume';
$cid1 = $origin_cid;
$cid2 = $cid;
break;
case 3:
case SWOOLE_CORO_END:
$state = 'close';
$cid1 = $cid;
$cid2 = $origin_cid;
Expand Down

0 comments on commit 9ea8df1

Please sign in to comment.