|
37 | 37 | #include "zend_arena.h"
|
38 | 38 |
|
39 | 39 | /* Unlike stdbool.h, not all supported compilers support stdatomic.h in C++
|
40 |
| - * mode. So, conditionally include <atomic> or <stdatomic.h> depending on |
41 |
| - * whether the compiler is in C++ mode or not. This restricts us to functions, |
42 |
| - * types, and macros which are present in both, which is a drag. |
| 40 | + * mode. There have beeen discussions to fix this for C++23/C23, but for |
| 41 | + * existing compilers there isn't much to do. Using C++'s std::atomic_bool |
| 42 | + * doesn't work because templates aren't available in extern C code. In this |
| 43 | + * case, fall back to no atomics. |
| 44 | + * TODO: move this stuff to a configure script because for this to be ABI safe, |
| 45 | + * a check that sizeof(atomic_bool) == sizeof(bool) needs to done. |
43 | 46 | */
|
44 |
| -#ifdef __cplusplus |
45 |
| -#include <atomic> |
46 |
| -using std::atomic_bool; |
47 |
| -#elif !defined(__STDC_NO_ATOMICS__) |
48 |
| -#include <stdatomic.h> |
49 |
| -#else |
| 47 | +#if defined(__cplusplus) || __STDC_VERSION__ < 201112L || defined(__STDC_NO_ATOMICS__) |
50 | 48 | // fall back to non-atomics
|
51 |
| -typedef bool atomic_bool |
| 49 | +typedef bool maybe_atomic_bool; |
| 50 | +#else |
| 51 | +#include <stdatomic.h> |
| 52 | +typedef atomic_bool maybe_atomic_bool; |
52 | 53 | #endif
|
53 | 54 |
|
54 | 55 | /* Define ZTS if you want a thread-safe Zend */
|
@@ -199,12 +200,8 @@ struct _zend_executor_globals {
|
199 | 200 |
|
200 | 201 | HashTable *in_autoload;
|
201 | 202 |
|
202 |
| - /* sizeof atomic_bool is not guaranteed to be the same as sizeof bool, |
203 |
| - * but it's somewhat common. The atomic_bools are left by the other |
204 |
| - * bools so that the struct packs nicely for such platforms. |
205 |
| - */ |
206 |
| - atomic_bool vm_interrupt; |
207 |
| - atomic_bool timed_out; |
| 203 | + maybe_atomic_bool vm_interrupt; |
| 204 | + maybe_atomic_bool timed_out; |
208 | 205 | bool full_tables_cleanup;
|
209 | 206 |
|
210 | 207 | /* for extended information support */
|
|
0 commit comments