Skip to content

Commit 277cced

Browse files
committed
Code optimization for scheduler API.
1 parent 296f7e9 commit 277cced

4 files changed

+15
-30
lines changed

swoole_coroutine.h

+9-15
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,22 @@ class PHPCoroutine
158158

159159
static inline bool enable_scheduler()
160160
{
161-
if (get_cid() > 0)
161+
php_coro_task *task = (php_coro_task *) Coroutine::get_current_task();
162+
if (task && task->enable_scheduler == 0)
162163
{
163-
php_coro_task *task = (php_coro_task *) Coroutine::get_current_task();
164-
if (task->enable_scheduler == 0)
165-
{
166-
task->enable_scheduler = 1;
167-
return true;
168-
}
164+
task->enable_scheduler = 1;
165+
return true;
169166
}
170167
return false;
171168
}
172169

173-
static inline bool disenable_scheduler()
170+
static inline bool disable_scheduler()
174171
{
175-
if (get_cid() > 0)
172+
php_coro_task *task = (php_coro_task *) Coroutine::get_current_task();
173+
if (task && task->enable_scheduler == 1)
176174
{
177-
php_coro_task *task = (php_coro_task *) Coroutine::get_current_task();
178-
if (task->enable_scheduler == 1)
179-
{
180-
task->enable_scheduler = 0;
181-
return true;
182-
}
175+
task->enable_scheduler = 0;
176+
return true;
183177
}
184178
return false;
185179
}

swoole_coroutine_scheduler.cc

+4-13
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,12 @@ PHP_METHOD(swoole_coroutine_scheduler, list)
290290
zval_ptr_dtor(&zlist);
291291
}
292292

293-
PHP_METHOD(swoole_coroutine_scheduler, disableScheduler)
293+
PHP_METHOD(swoole_coroutine_scheduler, enableScheduler)
294294
{
295-
if (PHPCoroutine::disenable_scheduler())
296-
{
297-
RETURN_TRUE;
298-
}
299-
RETURN_FALSE;
295+
RETURN_BOOL(PHPCoroutine::enable_scheduler());
300296
}
301297

302-
PHP_METHOD(swoole_coroutine_scheduler, enableScheduler)
298+
PHP_METHOD(swoole_coroutine_scheduler, disableScheduler)
303299
{
304-
if (PHPCoroutine::enable_scheduler())
305-
{
306-
RETURN_TRUE;
307-
}
308-
RETURN_FALSE;
300+
RETURN_BOOL(PHPCoroutine::disable_scheduler());
309301
}
310-

swoole_coroutine_scheduler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ PHP_METHOD(swoole_coroutine_scheduler, getPcid);
3030
PHP_METHOD(swoole_coroutine_scheduler, getContext);
3131
PHP_METHOD(swoole_coroutine_scheduler, getBackTrace);
3232
PHP_METHOD(swoole_coroutine_scheduler, list);
33-
PHP_METHOD(swoole_coroutine_scheduler, disableScheduler);
3433
PHP_METHOD(swoole_coroutine_scheduler, enableScheduler);
34+
PHP_METHOD(swoole_coroutine_scheduler, disableScheduler);

swoole_coroutine_util.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ static const zend_function_entry swoole_coroutine_util_methods[] =
141141
PHP_ME(swoole_coroutine_scheduler, getBackTrace, arginfo_swoole_coroutine_getBackTrace, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
142142
PHP_ME(swoole_coroutine_scheduler, list, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
143143
PHP_MALIAS(swoole_coroutine_scheduler, listCoroutines, list, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
144-
PHP_ME(swoole_coroutine_scheduler, disableScheduler, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
145144
PHP_ME(swoole_coroutine_scheduler, enableScheduler, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
145+
PHP_ME(swoole_coroutine_scheduler, disableScheduler, arginfo_swoole_coroutine_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
146146
/**
147147
* Coroutine System API
148148
*/

0 commit comments

Comments
 (0)