xref: /PHP-8.2/Zend/zend_atomic.c (revision 18cd80c3)
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_BOOL_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_bool_exchange(zend_atomic_bool * obj,bool desired)30 ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
31 	return zend_atomic_bool_exchange_ex(obj, desired);
32 }
33 
zend_atomic_bool_store(zend_atomic_bool * obj,bool desired)34 ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
35 	zend_atomic_bool_store_ex(obj, desired);
36 }
37 
38 #if defined(ZEND_WIN32) || defined(HAVE_SYNC_ATOMICS)
39 /* On these platforms it is non-const due to underlying APIs. */
zend_atomic_bool_load(zend_atomic_bool * obj)40 ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
41 	return zend_atomic_bool_load_ex(obj);
42 }
43 #else
zend_atomic_bool_load(const zend_atomic_bool * obj)44 ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
45 	return zend_atomic_bool_load_ex(obj);
46 }
47 #endif
48