diff --git a/ext-src/php_swoole_private.h b/ext-src/php_swoole_private.h index 65d1e475863..2bbbed78938 100644 --- a/ext-src/php_swoole_private.h +++ b/ext-src/php_swoole_private.h @@ -303,6 +303,11 @@ php_socket *php_swoole_convert_to_socket(int sock); zend_bool php_swoole_signal_isset_handler(int signo); +#if PHP_VERSION_ID < 80200 +# define zend_atomic_bool zend_bool +# define zend_atomic_bool_store(atomic, desired) (*atomic = desired) +#endif + #define sw_zend7_object zend_object #define SW_Z7_OBJ_P(object) object #define SW_Z8_OBJ_P(zobj) Z_OBJ_P(zobj) diff --git a/ext-src/swoole_coroutine.cc b/ext-src/swoole_coroutine.cc index bf55f841922..2e0a94eec67 100644 --- a/ext-src/swoole_coroutine.cc +++ b/ext-src/swoole_coroutine.cc @@ -64,7 +64,7 @@ bool PHPCoroutine::interrupt_thread_running = false; extern void php_swoole_load_library(); -static zend_bool *zend_vm_interrupt = nullptr; +static zend_atomic_bool *zend_vm_interrupt = nullptr; static user_opcode_handler_t ori_exit_handler = nullptr; static user_opcode_handler_t ori_begin_silence_handler = nullptr; static user_opcode_handler_t ori_end_silence_handler = nullptr; @@ -399,7 +399,7 @@ void PHPCoroutine::interrupt_thread_start() { interrupt_thread = std::thread([]() { swoole_signal_block_all(); while (interrupt_thread_running) { - *zend_vm_interrupt = 1; + zend_atomic_bool_store(zend_vm_interrupt, 1); std::this_thread::sleep_for(std::chrono::milliseconds(MAX_EXEC_MSEC / 2)); } });