xref: /PHP-8.4/Zend/zend_atomic.c (revision 1ab4520c)
1 /*
2    +----------------------------------------------------------------------+
3    | This source file is subject to version 3.01 of the PHP license,      |
4    | that is bundled with this package in the file LICENSE, and is        |
5    | available through the world-wide-web at the following url:           |
6    | https://www.php.net/license/3_01.txt                                 |
7    | If you did not receive a copy of the PHP license and are unable to   |
8    | obtain it through the world-wide-web, please send a note to          |
9    | license@php.net so we can mail you a copy immediately.               |
10    +----------------------------------------------------------------------+
11    | Authors: Levi Morrison <morrison.levi@gmail.com>                     |
12    +----------------------------------------------------------------------+
13  */
14 
15 #include "zend_atomic.h"
16 
17 /* This file contains the non-inline copy of atomic functions. This is useful
18  * for extensions written in languages such as Rust. C and C++ compilers are
19  * probably going to inline these functions, but in the case they don't, this
20  * is also where the code will go.
21  */
22 
23 /* Defined for FFI users; everyone else use ZEND_ATOMIC_*_INIT.
24  * This is NOT ATOMIC as it is meant for initialization.
25  */
zend_atomic_bool_init(zend_atomic_bool * obj,bool desired)26 ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired) {
27 	ZEND_ATOMIC_BOOL_INIT(obj, desired);
28 }
29 
zend_atomic_int_init(zend_atomic_int * obj,int desired)30 ZEND_API void zend_atomic_int_init(zend_atomic_int *obj, int desired) {
31 	ZEND_ATOMIC_INT_INIT(obj, desired);
32 }
33 
zend_atomic_bool_exchange(zend_atomic_bool * obj,bool desired)34 ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
35 	return zend_atomic_bool_exchange_ex(obj, desired);
36 }
37 
zend_atomic_int_exchange(zend_atomic_int * obj,int desired)38 ZEND_API int zend_atomic_int_exchange(zend_atomic_int *obj, int desired) {
39 	return zend_atomic_int_exchange_ex(obj, desired);
40 }
41 
zend_atomic_bool_compare_exchange(zend_atomic_bool * obj,bool * expected,bool desired)42 ZEND_API bool zend_atomic_bool_compare_exchange(zend_atomic_bool *obj, bool *expected, bool desired)
43 {
44 	return zend_atomic_bool_compare_exchange_ex(obj, expected, desired);
45 }
46 
zend_atomic_int_compare_exchange(zend_atomic_int * obj,int * expected,int desired)47 ZEND_API bool zend_atomic_int_compare_exchange(zend_atomic_int *obj, int *expected, int desired)
48 {
49 	return zend_atomic_int_compare_exchange_ex(obj, expected, desired);
50 }
51 
zend_atomic_bool_store(zend_atomic_bool * obj,bool desired)52 ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
53 	zend_atomic_bool_store_ex(obj, desired);
54 }
55 
zend_atomic_int_store(zend_atomic_int * obj,int desired)56 ZEND_API void zend_atomic_int_store(zend_atomic_int *obj, int desired) {
57 	zend_atomic_int_store_ex(obj, desired);
58 }
59 
60 #if defined(ZEND_WIN32) || defined(HAVE_SYNC_ATOMICS)
61 /* On these platforms it is non-const due to underlying APIs. */
zend_atomic_bool_load(zend_atomic_bool * obj)62 ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
63 	return zend_atomic_bool_load_ex(obj);
64 }
zend_atomic_int_load(zend_atomic_int * obj)65 ZEND_API int zend_atomic_int_load(zend_atomic_int *obj) {
66 	return zend_atomic_int_load_ex(obj);
67 }
68 #else
zend_atomic_bool_load(const zend_atomic_bool * obj)69 ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
70 	return zend_atomic_bool_load_ex(obj);
71 }
zend_atomic_int_load(const zend_atomic_int * obj)72 ZEND_API int zend_atomic_int_load(const zend_atomic_int *obj) {
73 	return zend_atomic_int_load_ex(obj);
74 }
75 #endif
76