@@ -63,61 +63,61 @@ BEGIN_EXTERN_C()
6363
6464#define ZEND_ATOMIC_BOOL_INIT (obj , desired ) ((obj)->value = (desired))
6565
66- inline ZEND_API bool zend_atomic_bool_exchange (zend_atomic_bool * obj , bool desired ) {
66+ static zend_always_inline bool zend_atomic_bool_exchange_ex (zend_atomic_bool * obj , bool desired ) {
6767 return InterlockedExchange8 (& obj -> value , desired );
6868}
6969
7070/* On this platform it is non-const due to Iterlocked API*/
71- inline ZEND_API bool zend_atomic_bool_load (zend_atomic_bool * obj ) {
71+ static zend_always_inline bool zend_atomic_bool_load_ex (zend_atomic_bool * obj ) {
7272 /* Or'ing with false won't change the value. */
7373 return InterlockedOr8 (& obj -> value , false);
7474}
7575
76- inline ZEND_API void zend_atomic_bool_store (zend_atomic_bool * obj , bool desired ) {
76+ static zend_always_inline void zend_atomic_bool_store_ex (zend_atomic_bool * obj , bool desired ) {
7777 (void )InterlockedExchange8 (& obj -> value , desired );
7878}
7979
8080#elif HAVE_C11_ATOMICS
8181
8282#define ZEND_ATOMIC_BOOL_INIT (obj , desired ) __c11_atomic_init(&(obj)->value, (desired))
8383
84- inline ZEND_API bool zend_atomic_bool_exchange (zend_atomic_bool * obj , bool desired ) {
84+ static zend_always_inline bool zend_atomic_bool_exchange_ex (zend_atomic_bool * obj , bool desired ) {
8585 return __c11_atomic_exchange (& obj -> value , desired , __ATOMIC_SEQ_CST );
8686}
8787
88- inline ZEND_API bool zend_atomic_bool_load (const zend_atomic_bool * obj ) {
88+ static zend_always_inline bool zend_atomic_bool_load_ex (const zend_atomic_bool * obj ) {
8989 return __c11_atomic_load (& obj -> value , __ATOMIC_SEQ_CST );
9090}
9191
92- inline ZEND_API void zend_atomic_bool_store (zend_atomic_bool * obj , bool desired ) {
92+ static zend_always_inline void zend_atomic_bool_store_ex (zend_atomic_bool * obj , bool desired ) {
9393 __c11_atomic_store (& obj -> value , desired , __ATOMIC_SEQ_CST );
9494}
9595
9696#elif HAVE_GNUC_ATOMICS
9797
9898#define ZEND_ATOMIC_BOOL_INIT (obj , desired ) ((obj)->value = (desired))
9999
100- inline ZEND_API bool zend_atomic_bool_exchange (zend_atomic_bool * obj , bool desired ) {
100+ static zend_always_inline bool zend_atomic_bool_exchange_ex (zend_atomic_bool * obj , bool desired ) {
101101 bool prev = false;
102102 __atomic_exchange (& obj -> value , & desired , & prev , __ATOMIC_SEQ_CST );
103103 return prev ;
104104}
105105
106- inline ZEND_API bool zend_atomic_bool_load (const zend_atomic_bool * obj ) {
106+ static zend_always_inline bool zend_atomic_bool_load_ex (const zend_atomic_bool * obj ) {
107107 bool prev = false;
108108 __atomic_load (& obj -> value , & prev , __ATOMIC_SEQ_CST );
109109 return prev ;
110110}
111111
112- inline ZEND_API void zend_atomic_bool_store (zend_atomic_bool * obj , bool desired ) {
112+ static zend_always_inline void zend_atomic_bool_store_ex (zend_atomic_bool * obj , bool desired ) {
113113 __atomic_store (& obj -> value , & desired , __ATOMIC_SEQ_CST );
114114}
115115
116116#elif HAVE_SYNC_ATOMICS
117117
118118#define ZEND_ATOMIC_BOOL_INIT (obj , desired ) ((obj)->value = (desired))
119119
120- inline ZEND_API bool zend_atomic_bool_exchange (zend_atomic_bool * obj , bool desired ) {
120+ static zend_always_inline bool zend_atomic_bool_exchange_ex (zend_atomic_bool * obj , bool desired ) {
121121 bool prev = __sync_lock_test_and_set (& obj -> value , desired );
122122
123123 /* __sync_lock_test_and_set only does an acquire barrier, so sync
@@ -127,12 +127,12 @@ inline ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desir
127127 return prev ;
128128}
129129
130- inline ZEND_API bool zend_atomic_bool_load (zend_atomic_bool * obj ) {
130+ static zend_always_inline bool zend_atomic_bool_load_ex (zend_atomic_bool * obj ) {
131131 /* Or'ing false won't change the value */
132132 return __sync_fetch_and_or (& obj -> value , false);
133133}
134134
135- inline ZEND_API void zend_atomic_bool_store (zend_atomic_bool * obj , bool desired ) {
135+ static zend_always_inline void zend_atomic_bool_store_ex (zend_atomic_bool * obj , bool desired ) {
136136 __sync_synchronize ();
137137 obj -> value = desired ;
138138 __sync_synchronize ();
@@ -147,25 +147,39 @@ inline ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired)
147147 * improvement. As more platforms support C11 atomics, or as we add support
148148 * for more platforms through intrinsics/asm, this should be used less and
149149 * less until it can be removed.
150- * At the time of this writing, all platforms in CI avoided this fallback.
150+ * At the time of this writing, all platforms in CI avoided this fallback,
151+ * so we emit an error. If there ends up being some platform that needs it,
152+ * we can remove the error or add support for whatever platform that is.
151153 */
154+ #error No atomics support detected. Please open an issue with platform deatils.
152155
153- inline ZEND_API void zend_atomic_bool_store (zend_atomic_bool * obj , bool desired ) {
156+ static zend_always_inline void zend_atomic_bool_store_ex (zend_atomic_bool * obj , bool desired ) {
154157 obj -> value = desired ;
155158}
156159
157- inline ZEND_API bool zend_atomic_bool_load (const zend_atomic_bool * obj ) {
160+ static zend_always_inline bool zend_atomic_bool_load_ex (const zend_atomic_bool * obj ) {
158161 return obj -> value ;
159162}
160163
161- inline ZEND_API bool zend_atomic_bool_exchange (zend_atomic_bool * obj , bool desired ) {
164+ static zend_always_inline bool zend_atomic_bool_exchange_ex (zend_atomic_bool * obj , bool desired ) {
162165 bool prev = obj -> value ;
163166 obj -> value = true;
164167 return prev ;
165168}
166169
167170#endif
168171
172+ ZEND_API void zend_atomic_bool_init (zend_atomic_bool * obj , bool desired );
173+ ZEND_API bool zend_atomic_bool_exchange (zend_atomic_bool * obj , bool desired );
174+ ZEND_API void zend_atomic_bool_store (zend_atomic_bool * obj , bool desired );
175+
176+ #if ZEND_WIN32 || HAVE_SYNC_ATOMICS
177+ /* On these platforms it is non-const due to underlying APIs. */
178+ ZEND_API bool zend_atomic_bool_load (zend_atomic_bool * obj );
179+ #else
180+ ZEND_API bool zend_atomic_bool_load (const zend_atomic_bool * obj );
181+ #endif
182+
169183END_EXTERN_C ()
170184
171185#endif
0 commit comments