Skip to content

Commit f3b3458

Browse files
committed
Make atomics compatible in more compiler modes
The typedef case is questionable; still thinking if it should error there. On one hand, the effect on the code is no different than what is used today, however, it may have the effect on programmers that it is actually atomic, which could be bad.
1 parent ae1bf94 commit f3b3458

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Zend/zend_globals.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define ZEND_GLOBALS_H
2222

2323
#include <setjmp.h>
24-
#include <stdatomic.h>
2524

2625
#include "zend_globals_macros.h"
2726

@@ -37,6 +36,21 @@
3736
#include "zend_multiply.h"
3837
#include "zend_arena.h"
3938

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.
43+
*/
44+
#ifdef __cplusplus
45+
#include <atomic>
46+
using std::atomic_bool;
47+
#elif !defined(__STDC_NO_ATOMICS__)
48+
#include <stdatomic.h>
49+
#else
50+
// fall back to non-atomics
51+
typedef bool atomic_bool
52+
#endif
53+
4054
/* Define ZTS if you want a thread-safe Zend */
4155
/*#undef ZTS*/
4256

0 commit comments

Comments
 (0)