[php-src] master: Zend: Remove zend_atomic.[ch] abstraction (#23927)
| From: | Marc via GitHub | Date: | Tue, 29 Sep 2026 14:30:34 +0000 |
| Subject: | [php-src] master: Zend: Remove zend_atomic.[ch] abstraction (#23927) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141681@lists.php.net to get a copy of this message | ||
Author: Marc (henderkes)
Committer: GitHub (web-flow)
Pusher: TimWolla
Date: 2026-09-29T16:30:30+02:00
Commit: https://github.com/php/php-src/commit/37d0ef5a66ce66dcf40dd568fda796fd41a97d9d
Raw diff: https://github.com/php/php-src/commit/37d0ef5a66ce66dcf40dd568fda796fd41a97d9d.diff
Zend: Remove zend_atomic.[ch] abstraction (#23927)
Changed paths:
D Zend/zend_atomic.c
D Zend/zend_atomic.h
M UPGRADING.INTERNALS
M Zend/zend_execute.c
M Zend/zend_execute_API.c
M Zend/zend_globals.h
M Zend/zend_portability.h
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
M configure.ac
M ext/opcache/ZendAccelerator.c
M ext/opcache/jit/zend_jit_trace.c
M ext/pcntl/pcntl.c
M ext/random/csprng.c
M ext/zend_test/object_handlers.c
M ext/zend_test/observer.c
M sapi/phpdbg/phpdbg_prompt.c
M win32/build/config.w32
M win32/signal.c
Diff:
diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index 0f79ee786aab..82f273974cd5 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -17,6 +17,8 @@ PHP 8.7 INTERNALS UPGRADE NOTES
- Removed zend_execute_scripts(). Manually call zend_execute_script() in a loop
instead.
- Removed ZEND_STATIC_ASSERT(). Use C11 static_assert() directly instead.
+- Removed zend_atomic.h and the zend_atomic_* types and functions.
+ Use the standard C11 atomic_* types and functions instead.
- The sapi_terminate_process() function was removed.
- The sapi_force_http_10() function was removed.
- The sapi_get_fd() function was removed.
@@ -33,8 +35,8 @@ PHP 8.7 INTERNALS UPGRADE NOTES
========================
- Windows build system changes:
- . C sources are now compiled as C17. MSVC builds require Visual Studio
- 2026 or later and enable /experimental:c11atomics.
+ . C sources are now compiled as C17 and require C11 atomics. MSVC builds require
+ Visual Studio 2026 or later and enable /experimental:c11atomics.
. C++-only extension compiler flags can be added to CXXFLAGS_<EXTENSION>.
- Unix build system changes:
diff --git a/Zend/zend_atomic.c b/Zend/zend_atomic.c
deleted file mode 100644
index 98a39c583437..000000000000
--- a/Zend/zend_atomic.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Copyright © The PHP Group and Contributors. |
- +----------------------------------------------------------------------+
- | This source file is subject to the Modified BSD License that is |
- | bundled with this package in the file LICENSE, and is available |
- | through the World Wide Web at <https://www.php.net/license/>. |
- | |
- | SPDX-License-Identifier: BSD-3-Clause |
- +----------------------------------------------------------------------+
- | Authors: Levi Morrison <morrison.levi@gmail.com> |
- +----------------------------------------------------------------------+
- */
-
-#include "zend_atomic.h"
-
-/* This file contains the non-inline copy of atomic functions. This is useful
- * for extensions written in languages such as Rust. C and C++ compilers are
- * probably going to inline these functions, but in the case they don't, this
- * is also where the code will go.
- */
-
-/* Defined for FFI users; everyone else use ZEND_ATOMIC_*_INIT.
- * This is NOT ATOMIC as it is meant for initialization.
- */
-ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired) {
- ZEND_ATOMIC_BOOL_INIT(obj, desired);
-}
-
-ZEND_API void zend_atomic_int_init(zend_atomic_int *obj, int desired) {
- ZEND_ATOMIC_INT_INIT(obj, desired);
-}
-
-ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
- return zend_atomic_bool_exchange_ex(obj, desired);
-}
-
-ZEND_API int zend_atomic_int_exchange(zend_atomic_int *obj, int desired) {
- return zend_atomic_int_exchange_ex(obj, desired);
-}
-
-ZEND_API bool zend_atomic_bool_compare_exchange(zend_atomic_bool *obj, bool *expected, bool
desired)
-{
- return zend_atomic_bool_compare_exchange_ex(obj, expected, desired);
-}
-
-ZEND_API bool zend_atomic_int_compare_exchange(zend_atomic_int *obj, int *expected, int desired)
-{
- return zend_atomic_int_compare_exchange_ex(obj, expected, desired);
-}
-
-ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
- zend_atomic_bool_store_ex(obj, desired);
-}
-
-ZEND_API void zend_atomic_int_store(zend_atomic_int *obj, int desired) {
- zend_atomic_int_store_ex(obj, desired);
-}
-
-#if (defined(ZEND_WIN32) || defined(HAVE_SYNC_ATOMICS)) && !defined(HAVE_C11_ATOMICS)
-/* On these platforms it is non-const due to underlying APIs. */
-ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
- return zend_atomic_bool_load_ex(obj);
-}
-ZEND_API int zend_atomic_int_load(zend_atomic_int *obj) {
- return zend_atomic_int_load_ex(obj);
-}
-#else
-ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
- return zend_atomic_bool_load_ex(obj);
-}
-ZEND_API int zend_atomic_int_load(const zend_atomic_int *obj) {
- return zend_atomic_int_load_ex(obj);
-}
-#endif
diff --git a/Zend/zend_atomic.h b/Zend/zend_atomic.h
deleted file mode 100644
index 5dee78c0570a..000000000000
--- a/Zend/zend_atomic.h
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Copyright © The PHP Group and Contributors. |
- +----------------------------------------------------------------------+
- | This source file is subject to the Modified BSD License that is |
- | bundled with this package in the file LICENSE, and is available |
- | through the World Wide Web at <https://www.php.net/license/>. |
- | |
- | SPDX-License-Identifier: BSD-3-Clause |
- +----------------------------------------------------------------------+
- | Authors: Levi Morrison <morrison.levi@gmail.com> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef ZEND_ATOMIC_H
-#define ZEND_ATOMIC_H
-
-#include "zend_portability.h"
-
-#include <stdbool.h>
-
-#define ZEND_GCC_PREREQ(x, y) \
- ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || (__GNUC__ > (x)))
-
-/* Builtins are used to avoid library linkage */
-#if __has_feature(c_atomic) && defined(__clang__)
-#define HAVE_C11_ATOMICS 1
-#elif ZEND_GCC_PREREQ(4, 7)
-#define HAVE_GNUC_ATOMICS 1
-#elif defined(__GNUC__)
-#define HAVE_SYNC_ATOMICS 1
-#elif !defined(ZEND_WIN32)
-#define HAVE_NO_ATOMICS 1
-#endif
-
-#undef ZEND_GCC_PREREQ
-
-/* Treat zend_atomic_* types as opaque. They have definitions only for size
- * and alignment purposes.
- */
-
-#if (defined(ZEND_WIN32) || defined(HAVE_SYNC_ATOMICS)) && !defined(HAVE_C11_ATOMICS)
-typedef struct zend_atomic_bool_s {
- volatile char value;
-} zend_atomic_bool;
-typedef struct zend_atomic_int_s {
-# ifdef ZEND_WIN32
- volatile long value;
-# else
- volatile int value;
-# endif
-} zend_atomic_int;
-#elif defined(HAVE_C11_ATOMICS)
-typedef struct zend_atomic_bool_s {
- _Atomic(bool) value;
-} zend_atomic_bool;
-typedef struct zend_atomic_int_s {
- _Atomic(int) value;
-} zend_atomic_int;
-#else
-typedef struct zend_atomic_bool_s {
- volatile bool value;
-} zend_atomic_bool;
-typedef struct zend_atomic_int_s {
- volatile int value;
-} zend_atomic_int;
-#endif
-
-BEGIN_EXTERN_C()
-
-#if defined(ZEND_WIN32) && !defined(HAVE_C11_ATOMICS)
-
-#ifndef InterlockedExchange8
-#define InterlockedExchange8 _InterlockedExchange8
-#endif
-#ifndef InterlockedOr8
-#define InterlockedOr8 _InterlockedOr8
-#endif
-#ifndef InterlockedCompareExchange8
-#define InterlockedCompareExchange8 _InterlockedCompareExchange8
-#endif
-#ifndef InterlockedExchange
-#define InterlockedExchange _InterlockedExchange
-#endif
-#ifndef InterlockedOr
-#define InterlockedOr _InterlockedOr
-#endif
-#ifndef InterlockedCompareExchange
-#define InterlockedCompareExchange _InterlockedCompareExchange
-#endif
-
-#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
-#define ZEND_ATOMIC_INT_INIT(obj, desired) ((obj)->value = (desired))
-
-#define ZEND_ATOMIC_BOOL_INITIALIZER(desired) {.value = (desired)}
-#define ZEND_ATOMIC_INT_INITIALIZER(desired) {.value = (desired)}
-
-static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
- return InterlockedExchange8(&obj->value, desired);
-}
-
-static zend_always_inline int zend_atomic_int_exchange_ex(zend_atomic_int *obj, int desired) {
- return (int) InterlockedExchange(&obj->value, desired);
-}
-
-static zend_always_inline bool zend_atomic_bool_compare_exchange_ex(zend_atomic_bool *obj, bool
*expected, bool desired) {
- bool prev = (bool) InterlockedCompareExchange8(&obj->value, *expected, desired);
- if (prev == *expected) {
- return true;
- } else {
- *expected = prev;
- return false;
- }
-}
-
-static zend_always_inline bool zend_atomic_int_compare_exchange_ex(zend_atomic_int *obj, int
*expected, int desired) {
- int prev = (int) InterlockedCompareExchange(&obj->value, *expected, desired);
- if (prev == *expected) {
- return true;
- } else {
- *expected = prev;
- return false;
- }
-}
-
-/* On this platform it is non-const due to Interlocked API */
-static zend_always_inline bool zend_atomic_bool_load_ex(zend_atomic_bool *obj) {
- /* Or'ing with false won't change the value. */
- return InterlockedOr8(&obj->value, false);
-}
-
-static zend_always_inline int zend_atomic_int_load_ex(zend_atomic_int *obj) {
- /* Or'ing with 0 won't change the value. */
- return (int) InterlockedOr(&obj->value, 0);
-}
-
-static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
- (void)InterlockedExchange8(&obj->value, desired);
-}
-
-static zend_always_inline void zend_atomic_int_store_ex(zend_atomic_int *obj, int desired) {
- (void)InterlockedExchange(&obj->value, desired);
-}
-
-#elif defined(HAVE_C11_ATOMICS)
-
-#define ZEND_ATOMIC_BOOL_INIT(obj, desired) __c11_atomic_init(&(obj)->value, (desired))
-#define ZEND_ATOMIC_INT_INIT(obj, desired) __c11_atomic_init(&(obj)->value, (desired))
-
-#define ZEND_ATOMIC_BOOL_INITIALIZER(desired) {.value = (desired)}
-#define ZEND_ATOMIC_INT_INITIALIZER(desired) {.value = (desired)}
-
-static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
- return __c11_atomic_exchange(&obj->value, desired, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline int zend_atomic_int_exchange_ex(zend_atomic_int *obj, int desired) {
- return __c11_atomic_exchange(&obj->value, desired, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline bool zend_atomic_bool_compare_exchange_ex(zend_atomic_bool *obj, bool
*expected, bool desired) {
- return __c11_atomic_compare_exchange_strong(&obj->value, expected, desired,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline bool zend_atomic_int_compare_exchange_ex(zend_atomic_int *obj, int
*expected, int desired) {
- return __c11_atomic_compare_exchange_strong(&obj->value, expected, desired,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline bool zend_atomic_bool_load_ex(const zend_atomic_bool *obj) {
- return __c11_atomic_load(&obj->value, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline int zend_atomic_int_load_ex(const zend_atomic_int *obj) {
- return __c11_atomic_load(&obj->value, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
- __c11_atomic_store(&obj->value, desired, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline void zend_atomic_int_store_ex(zend_atomic_int *obj, int desired) {
- __c11_atomic_store(&obj->value, desired, __ATOMIC_SEQ_CST);
-}
-
-#elif defined(HAVE_GNUC_ATOMICS)
-
-/* bool */
-
-#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
-#define ZEND_ATOMIC_INT_INIT(obj, desired) ((obj)->value = (desired))
-
-#define ZEND_ATOMIC_BOOL_INITIALIZER(desired) {.value = (desired)}
-#define ZEND_ATOMIC_INT_INITIALIZER(desired) {.value = (desired)}
-
-static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
- bool prev = false;
- __atomic_exchange(&obj->value, &desired, &prev, __ATOMIC_SEQ_CST);
- return prev;
-}
-
-static zend_always_inline int zend_atomic_int_exchange_ex(zend_atomic_int *obj, int desired) {
- int prev = false;
- __atomic_exchange(&obj->value, &desired, &prev, __ATOMIC_SEQ_CST);
- return prev;
-}
-
-static zend_always_inline bool zend_atomic_bool_compare_exchange_ex(zend_atomic_bool *obj, bool
*expected, bool desired) {
- return __atomic_compare_exchange(&obj->value, expected, &desired, /* weak */ false,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline bool zend_atomic_int_compare_exchange_ex(zend_atomic_int *obj, int
*expected, int desired) {
- return __atomic_compare_exchange(&obj->value, expected, &desired, /* weak */ false,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline bool zend_atomic_bool_load_ex(const zend_atomic_bool *obj) {
- bool prev = false;
- __atomic_load(&obj->value, &prev, __ATOMIC_SEQ_CST);
- return prev;
-}
-
-static zend_always_inline int zend_atomic_int_load_ex(const zend_atomic_int *obj) {
- int prev = false;
- __atomic_load(&obj->value, &prev, __ATOMIC_SEQ_CST);
- return prev;
-}
-
-static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
- __atomic_store(&obj->value, &desired, __ATOMIC_SEQ_CST);
-}
-
-static zend_always_inline void zend_atomic_int_store_ex(zend_atomic_int *obj, int desired) {
- __atomic_store(&obj->value, &desired, __ATOMIC_SEQ_CST);
-}
-
-#elif defined(HAVE_SYNC_ATOMICS)
-
-#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
-#define ZEND_ATOMIC_INT_INIT(obj, desired) ((obj)->value = (desired))
-
-#define ZEND_ATOMIC_BOOL_INITIALIZER(desired) {.value = (desired)}
-#define ZEND_ATOMIC_INT_INITIALIZER(desired) {.value = (desired)}
-
-static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
- bool prev = __sync_lock_test_and_set(&obj->value, desired);
-
- /* __sync_lock_test_and_set only does an acquire barrier, so sync
- * immediately after.
- */
- __sync_synchronize();
- return prev;
-}
-
-static zend_always_inline int zend_atomic_int_exchange_ex(zend_atomic_int *obj, int desired) {
- int prev = __sync_lock_test_and_set(&obj->value, desired);
-
- /* __sync_lock_test_and_set only does an acquire barrier, so sync
- * immediately after.
- */
- __sync_synchronize();
- return prev;
-}
-
-static zend_always_inline bool zend_atomic_bool_compare_exchange_ex(zend_atomic_bool *obj, bool
*expected, bool desired) {
- bool prev = __sync_val_compare_and_swap(&obj->value, *expected, desired);
- if (prev == *expected) {
- return true;
- } else {
- *expected = prev;
- return false;
- }
-}
-
-static zend_always_inline bool zend_atomic_int_compare_exchange_ex(zend_atomic_int *obj, int
*expected, int desired) {
- int prev = __sync_val_compare_and_swap(&obj->value, *expected, desired);
- if (prev == *expected) {
- return true;
- } else {
- *expected = prev;
- return false;
- }
-}
-
-static zend_always_inline bool zend_atomic_bool_load_ex(zend_atomic_bool *obj) {
- /* Or'ing false won't change the value */
- return __sync_fetch_and_or(&obj->value, false);
-}
-
-static zend_always_inline int zend_atomic_int_load_ex(zend_atomic_int *obj) {
- /* Or'ing 0 won't change the value */
- return __sync_fetch_and_or(&obj->value, 0);
-}
-
-static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
- __sync_synchronize();
- obj->value = desired;
- __sync_synchronize();
-}
-
-static zend_always_inline void zend_atomic_int_store_ex(zend_atomic_int *obj, int desired) {
- __sync_synchronize();
- obj->value = desired;
- __sync_synchronize();
-}
-
-#elif defined(HAVE_NO_ATOMICS)
-
-#warning No atomics support detected. Please open an issue with platform details.
-
-#define ZEND_ATOMIC_BOOL_INIT(obj, desired) ((obj)->value = (desired))
-#define ZEND_ATOMIC_INT_INIT(obj, desired) ((obj)->value = (desired))
-
-#define ZEND_ATOMIC_BOOL_INITIALIZER(desired) {.value = (desired)}
-#define ZEND_ATOMIC_INT_INITIALIZER(desired) {.value = (desired)}
-
-static zend_always_inline void zend_atomic_bool_store_ex(zend_atomic_bool *obj, bool desired) {
- obj->value = desired;
-}
-
-static zend_always_inline void zend_atomic_int_store_ex(zend_atomic_int *obj, int desired) {
- obj->value = desired;
-}
-
-static zend_always_inline bool zend_atomic_bool_compare_exchange_ex(zend_atomic_int *obj, bool
*expected, bool desired) {
- bool prev = obj->value;
- if (prev == *expected) {
- obj->value = desired;
- return true;
- } else {
- *expected = prev;
- return false;
- }
-}
-
-static zend_always_inline bool zend_atomic_int_compare_exchange_ex(zend_atomic_int *obj, int
*expected, int desired) {
- int prev = obj->value;
- if (prev == *expected) {
- obj->value = desired;
- return true;
- } else {
- *expected = prev;
- return false;
- }
-}
-
-static zend_always_inline bool zend_atomic_bool_load_ex(const zend_atomic_bool *obj) {
- return obj->value;
-}
-
-static zend_always_inline int zend_atomic_int_load_ex(const zend_atomic_int *obj) {
- return obj->value;
-}
-
-static zend_always_inline bool zend_atomic_bool_exchange_ex(zend_atomic_bool *obj, bool desired) {
- bool prev = obj->value;
- obj->value = desired;
- return prev;
-}
-
-static zend_always_inline int zend_atomic_int_exchange_ex(zend_atomic_int *obj, int desired) {
- int prev = obj->value;
- obj->value = desired;
- return prev;
-}
-
-#endif
-
-ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired);
-ZEND_API void zend_atomic_int_init(zend_atomic_int *obj, int desired);
-
-ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired);
-ZEND_API int zend_atomic_int_exchange(zend_atomic_int *obj, int desired);
-
-ZEND_API bool zend_atomic_bool_compare_exchange(zend_atomic_bool *obj, bool *expected, bool
desired);
-ZEND_API bool zend_atomic_int_compare_exchange(zend_atomic_int *obj, int *expected, int desired);
-
-ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired);
-ZEND_API void zend_atomic_int_store(zend_atomic_int *obj, int desired);
-
-#if (defined(ZEND_WIN32) && !defined(HAVE_C11_ATOMICS)) || defined(HAVE_SYNC_ATOMICS)
-/* On these platforms it is non-const due to underlying APIs. */
-ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj);
-ZEND_API int zend_atomic_int_load(zend_atomic_int *obj);
-#else
-ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj);
-ZEND_API int zend_atomic_int_load(const zend_atomic_int *obj);
-#endif
-
-#if defined(HAVE_C11_ATOMICS)
-# define ZEND_ATOMIC_FENCE_RELEASE() __c11_atomic_thread_fence(__ATOMIC_RELEASE)
-# define ZEND_ATOMIC_FENCE_ACQUIRE() __c11_atomic_thread_fence(__ATOMIC_ACQUIRE)
-#elif defined(HAVE_GNUC_ATOMICS)
-# define ZEND_ATOMIC_FENCE_RELEASE() __atomic_thread_fence(__ATOMIC_RELEASE)
-# define ZEND_ATOMIC_FENCE_ACQUIRE() __atomic_thread_fence(__ATOMIC_ACQUIRE)
-#elif defined(HAVE_SYNC_ATOMICS)
-# define ZEND_ATOMIC_FENCE_RELEASE() __sync_synchronize()
-# define ZEND_ATOMIC_FENCE_ACQUIRE() __sync_synchronize()
-#elif defined(ZEND_WIN32)
-# define ZEND_ATOMIC_FENCE_RELEASE() MemoryBarrier()
-# define ZEND_ATOMIC_FENCE_ACQUIRE() MemoryBarrier()
-#else
-# define ZEND_ATOMIC_FENCE_RELEASE() ((void)0)
-# define ZEND_ATOMIC_FENCE_ACQUIRE() ((void)0)
-#endif
-
-END_EXTERN_C()
-
-#endif
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index a5f9d1e8c848..ff3a5f0b3de9 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -4344,8 +4344,8 @@ ZEND_API void ZEND_FASTCALL zend_free_compiled_variables(zend_execute_data
*exec
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data *call)
{
- zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ atomic_store(&EG(vm_interrupt), false);
+ if (atomic_load(&EG(timed_out))) {
zend_timeout();
} else if (zend_interrupt_function) {
zend_interrupt_function(call);
@@ -4353,7 +4353,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data
*ca
}
#define ZEND_VM_INTERRUPT_CHECK() do { \
- if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
+ if (UNEXPECTED(atomic_load(&EG(vm_interrupt)))) { \
ZEND_VM_INTERRUPT(); \
} \
} while (0)
@@ -4365,14 +4365,14 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_fcall_interrupt(zend_execute_data
*ca
#endif
#define ZEND_VM_LOOP_INTERRUPT_CHECK() do { \
- if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
+ if (UNEXPECTED(atomic_load(&EG(vm_interrupt)))) { \
ZEND_VM_KIND_TAILCALL_SAVE_OPLINE(); \
ZEND_VM_LOOP_INTERRUPT(); \
} \
} while (0)
#define ZEND_VM_FCALL_INTERRUPT_CHECK(call) do { \
- if (UNEXPECTED(zend_atomic_bool_load_ex(&EG(vm_interrupt)))) { \
+ if (UNEXPECTED(atomic_load(&EG(vm_interrupt)))) { \
zend_fcall_interrupt(call); \
} \
} while (0)
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index 900487cf3898..7910c840a17b 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -172,8 +172,8 @@ void init_executor(void) /* {{{ */
zend_lazy_objects_init(&EG(lazy_objects_store));
EG(full_tables_cleanup) = 0;
- ZEND_ATOMIC_BOOL_INIT(&EG(vm_interrupt), false);
- ZEND_ATOMIC_BOOL_INIT(&EG(timed_out), false);
+ atomic_init(&EG(vm_interrupt), false);
+ atomic_init(&EG(timed_out), false);
EG(exception) = NULL;
@@ -1099,8 +1099,8 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache
*fci_
/* This flag is regularly checked while running user functions, but not internal
* So see whether interrupt flag was set while the function was running... */
- if (zend_atomic_bool_exchange_ex(&EG(vm_interrupt), false)) {
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ if (atomic_exchange(&EG(vm_interrupt), false)) {
+ if (atomic_load(&EG(timed_out))) {
zend_timeout();
} else if (zend_interrupt_function) {
zend_interrupt_function(EG(current_execute_data));
@@ -1476,14 +1476,14 @@ ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void) /* {{{ */
timer is not restarted properly, it could hang in the shutdown
function. */
if (EG(hard_timeout) > 0) {
- zend_atomic_bool_store_ex(&EG(timed_out), false);
+ atomic_store(&EG(timed_out), false);
zend_set_timeout_ex(EG(hard_timeout), true);
/* XXX Abused, introduce an additional flag if the value needs to be kept. */
EG(hard_timeout) = 0;
}
# endif
#else
- zend_atomic_bool_store_ex(&EG(timed_out), false);
+ atomic_store(&EG(timed_out), false);
zend_set_timeout_ex(0, true);
#endif
@@ -1528,7 +1528,7 @@ static void zend_timeout_handler(int dummy) /* {{{ */
return;
}
#else
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ if (atomic_load(&EG(timed_out))) {
/* Die on hard timeout */
const char *error_filename = NULL;
uint32_t error_lineno = 0;
@@ -1563,8 +1563,8 @@ static void zend_timeout_handler(int dummy) /* {{{ */
zend_on_timeout(EG(timeout_seconds));
}
- zend_atomic_bool_store_ex(&EG(timed_out), true);
- zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
+ atomic_store(&EG(timed_out), true);
+ atomic_store(&EG(vm_interrupt), true);
#ifndef ZTS
if (EG(hard_timeout) > 0) {
@@ -1588,8 +1588,8 @@ VOID CALLBACK tq_timer_cb(PVOID arg, BOOLEAN timed_out)
}
eg = (zend_executor_globals *)arg;
- zend_atomic_bool_store_ex(&eg->timed_out, true);
- zend_atomic_bool_store_ex(&eg->vm_interrupt, true);
+ atomic_store(&eg->timed_out, true);
+ atomic_store(&eg->vm_interrupt, true);
}
#endif
@@ -1697,7 +1697,7 @@ void zend_set_timeout(zend_long seconds, bool reset_signals) /* {{{ */
EG(timeout_seconds) = seconds;
zend_set_timeout_ex(seconds, reset_signals);
- zend_atomic_bool_store_ex(&EG(timed_out), false);
+ atomic_store(&EG(timed_out), false);
}
/* }}} */
@@ -1706,7 +1706,7 @@ void zend_unset_timeout(void) /* {{{ */
#ifdef ZEND_WIN32
if (NULL != tq_timer) {
if (!DeleteTimerQueueTimer(NULL, tq_timer, INVALID_HANDLE_VALUE)) {
- zend_atomic_bool_store_ex(&EG(timed_out), false);
+ atomic_store(&EG(timed_out), false);
tq_timer = NULL;
zend_error_noreturn(E_ERROR, "Could not delete queued timer");
}
@@ -1729,7 +1729,7 @@ void zend_unset_timeout(void) /* {{{ */
# endif
}
#endif
- zend_atomic_bool_store_ex(&EG(timed_out), false);
+ atomic_store(&EG(timed_out), false);
}
/* }}} */
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index b7835ed63226..d74bd8e63447 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -26,7 +26,6 @@
#include "zend_globals_macros.h"
-#include "zend_atomic.h"
#include "zend_stack.h"
#include "zend_ptr_stack.h"
#include "zend_hash.h"
@@ -223,8 +222,8 @@ struct _zend_executor_globals {
bool full_tables_cleanup;
- zend_atomic_bool vm_interrupt;
- zend_atomic_bool timed_out;
+ atomic_bool vm_interrupt;
+ atomic_bool timed_out;
HashTable autoload_current_classnames;
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index 0ffd8baa2cfa..a3028efe172b 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -52,6 +52,23 @@
#include <assert.h>
#include <math.h>
+#ifdef __cplusplus
+extern "C++" {
+# include <atomic>
+/* Make the atomic types used by Zend available to C++ extensions. */
+using std::atomic_bool;
+using std::atomic_int;
+}
+#else
+# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
+# error "Zend requires C11 or later"
+# endif
+# ifdef __STDC_NO_ATOMICS__
+# error "Zend requires C11 atomics"
+# endif
+# include <stdatomic.h>
+#endif
+
#ifdef HAVE_UNIX_H
# include <unix.h>
#endif
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index c0fd2eef277b..be69d2624cfd 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -10711,14 +10711,14 @@ ZEND_VM_DEFINE_OP(137, ZEND_OP_DATA);
ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY)
{
- zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
+ atomic_store(&EG(vm_interrupt), false);
#if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL
/* opline is &call_interrupt_op. Load orig opline. */
LOAD_OPLINE();
#else
SAVE_OPLINE();
#endif
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ if (atomic_load(&EG(timed_out))) {
zend_timeout();
} else if (zend_interrupt_function) {
zend_interrupt_function(execute_data);
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index b956b638b7e4..5e5677a9f0b1 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -4032,14 +4032,14 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV
ZEND_J
static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV
zend_interrupt_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
{
- zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
+ atomic_store(&EG(vm_interrupt), false);
#if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL
/* opline is &call_interrupt_op. Load orig opline. */
LOAD_OPLINE();
#else
SAVE_OPLINE();
#endif
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ if (atomic_load(&EG(timed_out))) {
zend_timeout();
} else if (zend_interrupt_function) {
zend_interrupt_function(execute_data);
@@ -56877,14 +56877,14 @@ static ZEND_VM_HOT ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV
ZEND_JMP_FO
static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_CCONV
zend_interrupt_helper_SPEC_TAILCALL(ZEND_OPCODE_HANDLER_ARGS)
{
- zend_atomic_bool_store_ex(&EG(vm_interrupt), false);
+ atomic_store(&EG(vm_interrupt), false);
#if ZEND_VM_KIND == ZEND_VM_KIND_TAILCALL
/* opline is &call_interrupt_op. Load orig opline. */
LOAD_OPLINE();
#else
SAVE_OPLINE();
#endif
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ if (atomic_load(&EG(timed_out))) {
zend_timeout();
} else if (zend_interrupt_function) {
zend_interrupt_function(execute_data);
diff --git a/configure.ac b/configure.ac
index 50df06a6b479..f48f1e8de90e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1757,7 +1757,6 @@ PHP_ADD_SOURCES([Zend], m4_normalize([
zend_alloc.c
zend_API.c
zend_ast.c
- zend_atomic.c
zend_attributes.c
zend_autoload.c
zend_builtin_functions.c
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 9d6167ba73e3..4e4c815377ac 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -2541,7 +2541,7 @@ static zend_class_entry* zend_accel_inheritance_cache_get(zend_class_entry
*ce,
zend_inheritance_cache_entry *entry = ce->inheritance_cache;
if (entry) {
- ZEND_ATOMIC_FENCE_ACQUIRE();
+ atomic_thread_fence(memory_order_acquire);
}
while (entry) {
@@ -2702,7 +2702,7 @@ static zend_class_entry* zend_accel_inheritance_cache_add(zend_class_entry
*ce,
entry->next = proto->inheritance_cache;
ZCSG(map_ptr_last) = CG(map_ptr_last);
- ZEND_ATOMIC_FENCE_RELEASE();
+ atomic_thread_fence(memory_order_release);
proto->inheritance_cache = entry;
zend_shared_alloc_destroy_xlat_table();
diff --git a/ext/opcache/jit/zend_jit_trace.c b/ext/opcache/jit/zend_jit_trace.c
index 45936ba01f48..21c15630bdf8 100644
--- a/ext/opcache/jit/zend_jit_trace.c
+++ b/ext/opcache/jit/zend_jit_trace.c
@@ -8836,7 +8836,7 @@ int ZEND_FASTCALL zend_jit_trace_exit(uint32_t exit_num,
zend_jit_registers_buf
EX(opline) = opline;
}
- if (zend_atomic_bool_load_ex(&EG(vm_interrupt)) || JIT_G(tracing)) {
+ if (atomic_load(&EG(vm_interrupt)) || JIT_G(tracing)) {
return 1;
/* Lock-free check if the side trace was already JIT-ed or blacklist-ed in another process */
} else if (t->exit_info[exit_num].flags & (ZEND_JIT_EXIT_JITED|ZEND_JIT_EXIT_BLACKLISTED))
{
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 0646e7ba043f..3a4d8ee7e25c 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -1345,7 +1345,7 @@ static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
PCNTL_G(tail) = psig;
PCNTL_G(pending_signals) = true;
if (PCNTL_G(async_signals)) {
- zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
+ atomic_store(&EG(vm_interrupt), true);
}
}
@@ -1453,7 +1453,7 @@ void pcntl_signal_dispatch(void)
PCNTL_G(tail) = next;
if (PCNTL_G(async_signals)) {
- zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
+ atomic_store(&EG(vm_interrupt), true);
}
} else {
PCNTL_G(pending_signals) = false;
diff --git a/ext/random/csprng.c b/ext/random/csprng.c
index 4c474fb86796..b6333aaea284 100644
--- a/ext/random/csprng.c
+++ b/ext/random/csprng.c
@@ -24,7 +24,6 @@
#include "php.h"
#include "Zend/zend_exceptions.h"
-#include "Zend/zend_atomic.h"
#include "php_random.h"
#include "php_random_csprng.h"
@@ -61,7 +60,7 @@
#endif
#ifndef PHP_WIN32
-static zend_atomic_int random_fd = ZEND_ATOMIC_INT_INITIALIZER(-1);
+static atomic_int random_fd = -1;
#endif
ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_bytes_ex(void *bytes, size_t size, char
*errstr, size_t errstr_size)
@@ -146,7 +145,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_bytes_ex(void *bytes, size_
}
# endif
if (read_bytes < size) {
- int fd = zend_atomic_int_load_ex(&random_fd);
+ int fd = atomic_load(&random_fd);
struct stat st;
if (fd < 0) {
@@ -179,7 +178,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_bytes_ex(void *bytes, size_
return FAILURE;
}
int expected = -1;
- if (!zend_atomic_int_compare_exchange_ex(&random_fd, &expected, fd)) {
+ if (!atomic_compare_exchange_strong(&random_fd, &expected, fd)) {
close(fd);
/* expected is now the actual value of random_fd */
fd = expected;
@@ -265,7 +264,7 @@ ZEND_ATTRIBUTE_NONNULL PHPAPI zend_result php_random_int(zend_long min, zend_lon
PHPAPI void php_random_csprng_shutdown(void)
{
#ifndef PHP_WIN32
- int fd = zend_atomic_int_exchange(&random_fd, -1);
+ int fd = atomic_exchange(&random_fd, -1);
if (fd != -1) {
close(fd);
}
diff --git a/ext/zend_test/object_handlers.c b/ext/zend_test/object_handlers.c
index 6b8bf4ab9912..9e78e9fdf524 100644
--- a/ext/zend_test/object_handlers.c
+++ b/ext/zend_test/object_handlers.c
@@ -250,7 +250,7 @@ static int vm_interrupt_comparable_compare(zval *op1, zval *op2)
{
ZEND_COMPARE_OBJECTS_FALLBACK(op1, op2);
- zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
+ atomic_store(&EG(vm_interrupt), true);
return ZEND_THREEWAY_COMPARE(
Z_LVAL_P(OBJ_PROP_NUM(Z_OBJ_P(op1), 0)),
diff --git a/ext/zend_test/observer.c b/ext/zend_test/observer.c
index 2fd4073b4af0..77ce0cc2525e 100644
--- a/ext/zend_test/observer.c
+++ b/ext/zend_test/observer.c
@@ -76,7 +76,7 @@ static void observer_begin(zend_execute_data *execute_data)
assert_observer_opline(execute_data);
if (ZT_G(observer_set_vm_interrupt_on_begin)) {
- zend_atomic_bool_store_ex(&EG(vm_interrupt), true);
+ atomic_store(&EG(vm_interrupt), true);
}
if (!ZT_G(observer_show_output)) {
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index 88afd1b3752e..b879cde43653 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -1652,7 +1652,7 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
}
#ifdef ZEND_WIN32
- if (zend_atomic_bool_load_ex(&EG(timed_out))) {
+ if (atomic_load(&EG(timed_out))) {
zend_timeout();
}
#endif
diff --git a/win32/build/config.w32 b/win32/build/config.w32
index f352d4c794aa..253dab653986 100644
--- a/win32/build/config.w32
+++ b/win32/build/config.w32
@@ -240,7 +240,7 @@ ADD_SOURCES("Zend", "zend_language_parser.c
zend_language_scanner.c \
zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c zend_weakrefs.c \
zend_float.c zend_string.c zend_generators.c zend_virtual_cwd.c zend_ast.c \
zend_inheritance.c zend_smart_str.c zend_cpuinfo.c zend_observer.c zend_system_id.c \
- zend_enum.c zend_fibers.c zend_atomic.c zend_hrtime.c zend_frameless_function.c
zend_property_hooks.c \
+ zend_enum.c zend_fibers.c zend_hrtime.c zend_frameless_function.c zend_property_hooks.c \
zend_lazy_objects.c zend_autoload.c zend_partial.c");
ADD_SOURCES("Zend\\Optimizer", "zend_optimizer.c pass1.c pass3.c
optimize_func_calls.c block_pass.c optimize_temp_vars_5.c nop_removal.c compact_literals.c
zend_cfg.c zend_dfg.c dfa_pass.c zend_ssa.c zend_inference.c zend_func_info.c zend_call_graph.c
zend_dump.c escape_analysis.c compact_vars.c dce.c sccp.c scdf.c");
diff --git a/win32/signal.c b/win32/signal.c
index abce3edb2fd1..1cf917d595a0 100644
--- a/win32/signal.c
+++ b/win32/signal.c
@@ -20,7 +20,7 @@
/* true globals; only used from main thread and from kernel callback */
static zend_fcall_info_cache ctrl_handler;
static DWORD ctrl_evt = (DWORD)-1;
-static zend_atomic_bool *vm_interrupt_flag = NULL;
+static atomic_bool *vm_interrupt_flag = NULL;
static void (*orig_interrupt_function)(zend_execute_data *execute_data);
@@ -91,7 +91,7 @@ static BOOL WINAPI php_win32_signal_system_ctrl_handler(DWORD evt)
return FALSE;
}
- zend_atomic_bool_store_ex(vm_interrupt_flag, true);
+ atomic_store(vm_interrupt_flag, true);
ctrl_evt = evt;