diff --git a/ext-src/php_swoole_private.h b/ext-src/php_swoole_private.h index b6a5379157..3ebbdfde6d 100644 --- a/ext-src/php_swoole_private.h +++ b/ext-src/php_swoole_private.h @@ -512,7 +512,13 @@ static inline bool sw_is_main_thread() { #endif } -size_t sw_get_active_thread_count(void); +#ifdef SW_THREAD +size_t sw_active_thread_count(void); +#else +static inline size_t sw_active_thread_count(void) { + return 1; +} +#endif void sw_php_exit(int status); //----------------------------------Constant API------------------------------------ diff --git a/ext-src/swoole_runtime.cc b/ext-src/swoole_runtime.cc index 9785f386cc..0d292c6b2e 100644 --- a/ext-src/swoole_runtime.cc +++ b/ext-src/swoole_runtime.cc @@ -1645,7 +1645,7 @@ bool PHPCoroutine::enable_hook(uint32_t flags) { * the main thread can only make changes when there are no active worker threads. */ if (sw_is_main_thread()) { - if (sw_get_active_thread_count() > 1) { + if (sw_active_thread_count() > 1) { zend_throw_exception(swoole_exception_ce, "The stream runtime hook must be enabled or disabled only when " "there are no active threads.", diff --git a/ext-src/swoole_thread.cc b/ext-src/swoole_thread.cc index c8d581b62e..6969620643 100644 --- a/ext-src/swoole_thread.cc +++ b/ext-src/swoole_thread.cc @@ -380,9 +380,9 @@ void php_swoole_thread_rshutdown() { if (!tsrm_is_main_thread()) { return; } - if (sw_get_active_thread_count() > 1) { + if (sw_active_thread_count() > 1) { swoole_warning("Fatal Error: %zu active threads are running, cannot exit safely.", - sw_get_active_thread_count()); + sw_active_thread_count()); exit(200); } if (request_info.path_translated) { @@ -507,7 +507,7 @@ int php_swoole_thread_get_exit_status(pthread_t ptid) { return thread_exit_status.get(ptid); } -size_t sw_get_active_thread_count(void) { +size_t sw_active_thread_count(void) { return thread_num.load(); }