diff --git a/src/runtime.h b/src/runtime.h index 5f8fdd1..41b5887 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -18,9 +18,12 @@ #ifndef HAVE_PARALLEL_RUNTIME_H #define HAVE_PARALLEL_RUNTIME_H -#if PHP_VERSION_ID < 80200 -#define zend_atomic_bool bool -#define zend_atomic_bool_store(dest, value) (*(dest) = value) +#if PHP_VERSION_ID >= 80700 +typedef atomic_bool php_parallel_interrupt_t; +#elif PHP_VERSION_ID >= 80200 +typedef zend_atomic_bool php_parallel_interrupt_t; +#else +typedef bool php_parallel_interrupt_t; #endif typedef struct _php_parallel_runtime_t { @@ -28,7 +31,7 @@ typedef struct _php_parallel_runtime_t { php_parallel_monitor_t *monitor; zend_string *bootstrap; struct { - zend_atomic_bool *interrupt; + php_parallel_interrupt_t *interrupt; } child; struct { void *server; diff --git a/src/scheduler.c b/src/scheduler.c index dfa8494..1dd6f5f 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -743,6 +743,17 @@ void php_parallel_scheduler_push(php_parallel_runtime_t *runtime, zval *closure, php_parallel_monitor_unlock(runtime->monitor); } +static zend_always_inline void php_parallel_scheduler_request_interrupt(php_parallel_runtime_t *runtime) +{ +#if PHP_VERSION_ID >= 80700 + atomic_store(runtime->child.interrupt, true); +#elif PHP_VERSION_ID >= 80200 + zend_atomic_bool_store(runtime->child.interrupt, true); +#else + *runtime->child.interrupt = true; +#endif +} + void php_parallel_scheduler_join(php_parallel_runtime_t *runtime, bool kill) { php_parallel_monitor_lock(runtime->monitor); @@ -756,7 +767,7 @@ void php_parallel_scheduler_join(php_parallel_runtime_t *runtime, bool kill) if (kill) { php_parallel_monitor_set(runtime->monitor, PHP_PARALLEL_KILLED); - zend_atomic_bool_store(runtime->child.interrupt, true); + php_parallel_scheduler_request_interrupt(runtime); } else { php_parallel_monitor_set(runtime->monitor, PHP_PARALLEL_CLOSE); } @@ -790,7 +801,7 @@ bool php_parallel_scheduler_cancel(php_parallel_future_t *future) php_parallel_monitor_lock(future->monitor); if (!php_parallel_monitor_check(future->monitor, PHP_PARALLEL_READY)) { - zend_atomic_bool_store(future->runtime->child.interrupt, true); + php_parallel_scheduler_request_interrupt(future->runtime); php_parallel_monitor_set(future->monitor, PHP_PARALLEL_CANCELLED); php_parallel_monitor_wait_locked(future->monitor, PHP_PARALLEL_READY);