php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_atomic.c
Go to the documentation of this file.
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 */
27 ZEND_ATOMIC_BOOL_INIT(obj, desired);
28}
29
31 ZEND_ATOMIC_INT_INIT(obj, desired);
32}
33
35 return zend_atomic_bool_exchange_ex(obj, desired);
36}
37
39 return zend_atomic_int_exchange_ex(obj, desired);
40}
41
42ZEND_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
47ZEND_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
53 zend_atomic_bool_store_ex(obj, desired);
54}
55
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. */
63 return zend_atomic_bool_load_ex(obj);
64}
66 return zend_atomic_int_load_ex(obj);
67}
68#else
70 return zend_atomic_bool_load_ex(obj);
71}
73 return zend_atomic_int_load_ex(obj);
74}
75#endif
ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired)
Definition zend_atomic.c:52
ZEND_API int zend_atomic_int_load(const zend_atomic_int *obj)
Definition zend_atomic.c:72
ZEND_API bool zend_atomic_int_compare_exchange(zend_atomic_int *obj, int *expected, int desired)
Definition zend_atomic.c:47
ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired)
Definition zend_atomic.c:34
ZEND_API void zend_atomic_int_store(zend_atomic_int *obj, int desired)
Definition zend_atomic.c:56
ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj)
Definition zend_atomic.c:69
ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired)
Definition zend_atomic.c:26
ZEND_API int zend_atomic_int_exchange(zend_atomic_int *obj, int desired)
Definition zend_atomic.c:38
ZEND_API void zend_atomic_int_init(zend_atomic_int *obj, int desired)
Definition zend_atomic.c:30
ZEND_API bool zend_atomic_bool_compare_exchange(zend_atomic_bool *obj, bool *expected, bool desired)
Definition zend_atomic.c:42
struct zend_atomic_int_s zend_atomic_int
#define ZEND_ATOMIC_INT_INIT(obj, desired)
#define ZEND_ATOMIC_BOOL_INIT(obj, desired)
struct zend_atomic_bool_s zend_atomic_bool
#define ZEND_API