Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Nov 24, 2018
1 parent 98607d1 commit 8e59e8f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
18 changes: 15 additions & 3 deletions include/coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ namespace swoole
{
class Coroutine
{
public:
swoole::Context ctx;
private:
long cid;
sw_coro_state state;
void *task;
swoole::Context ctx;

public:
sw_coro_state state;

Coroutine(long _cid, size_t stack_size, coroutine_func_t fn, void *private_data) :
ctx(stack_size, fn, private_data)
Expand Down Expand Up @@ -76,6 +78,11 @@ class Coroutine
return cid;
}

inline void* get_task()
{
return task;
}

static long create(coroutine_func_t fn, void* args);
static int sleep(double sec);
static swString* read_file(const char *file, int lock);
Expand All @@ -97,6 +104,11 @@ void coroutine_set_onResume(coro_php_resume_t func);
void coroutine_set_onResumeBack(coro_php_resume_t func);
void coroutine_set_onClose(coro_php_close_t func);

inline static long coroutine_get_cid(swoole::Coroutine* co)
{
return co ? co->get_cid() : -1;
}

void internal_coro_yield(void *arg);
void internal_coro_resume(void *arg);

Expand Down
6 changes: 3 additions & 3 deletions src/coroutine/base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void* coroutine_get_task_by_cid(long cid)
}
else
{
return co->task;
return co->get_task();
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ void* coroutine_get_current_task()
}
else
{
return co->task;
return co->get_task();
}
}

Expand All @@ -161,7 +161,7 @@ std::unordered_map<long, Coroutine*>* coroutine_get_map()
long coroutine_get_current_cid()
{
Coroutine* co = coroutine_get_current();
return likely(co) ? co->cid : -1;
return likely(co) ? co->get_cid() : -1;
}

void coroutine_set_onYield(coro_php_yield_t func)
Expand Down
6 changes: 3 additions & 3 deletions swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static void php_coro_create(void *arg)

swTraceLog(
SW_TRACE_COROUTINE, "Create coro id: %ld, origin cid: %ld, coro total count: %" PRIu64 ", heap size: %zu",
task->co->get_cid(), task->origin_task->co->get_cid(), COROG.coro_num, zend_memory_usage(0)
coroutine_get_cid(task->co), coroutine_get_cid(task->origin_task->co), COROG.coro_num, zend_memory_usage(0)
);

if (SwooleG.hooks[SW_GLOBAL_HOOK_ON_CORO_START])
Expand Down Expand Up @@ -294,7 +294,7 @@ static void php_coro_create(void *arg)

static sw_inline void php_coro_yield(coro_task *task)
{
swTraceLog(SW_TRACE_COROUTINE,"php_coro_yield from cid=%ld to cid=%ld", task->co->get_cid(), task->origin_task->co->get_cid());
swTraceLog(SW_TRACE_COROUTINE,"php_coro_yield from cid=%ld to cid=%ld", coroutine_get_cid(task->co), coroutine_get_cid(task->origin_task->co));
php_coro_save_vm_stack(task);
php_coro_restore_vm_stack(task->origin_task);
php_coro_og_yield(task);
Expand All @@ -305,7 +305,7 @@ static sw_inline void php_coro_resume(coro_task *task)
task->origin_task = php_coro_get_current_task();
php_coro_restore_vm_stack(task);
php_coro_og_resume(task);
swTraceLog(SW_TRACE_COROUTINE,"php_coro_resume from cid=%ld to cid=%ld", task->origin_task->co->get_cid(), task->co->get_cid());
swTraceLog(SW_TRACE_COROUTINE,"php_coro_resume from cid=%ld to cid=%ld", coroutine_get_cid(task->origin_task->co), coroutine_get_cid(task->co));
}

static sw_inline void php_coro_close(coro_task *task)
Expand Down
4 changes: 2 additions & 2 deletions swoole_coroutine_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static PHP_METHOD(swoole_coroutine_util, yield)
swoole_php_fatal_error(E_ERROR, "can not yield outside coroutine");
RETURN_FALSE;
}
user_yield_coros[co->cid] = co;
user_yield_coros[co->get_cid()] = co;
co->yield();
RETURN_TRUE;
}
Expand Down Expand Up @@ -1333,7 +1333,7 @@ static PHP_METHOD(swoole_coroutine_iterator, current)
{
coroutine_iterator *itearator = (coroutine_iterator *) swoole_get_object(getThis());
Coroutine *co = itearator->_cursor->second;
RETURN_LONG(co->cid);
RETURN_LONG(co->get_cid());
}

static PHP_METHOD(swoole_coroutine_iterator, next)
Expand Down

0 comments on commit 8e59e8f

Please sign in to comment.