Coverage Report

Created: 2025-06-13 06:43

/src/php-src/Zend/zend_atomic.c
Line
Count
Source (jump to first uncovered line)
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
 */
26
0
ZEND_API void zend_atomic_bool_init(zend_atomic_bool *obj, bool desired) {
27
0
  ZEND_ATOMIC_BOOL_INIT(obj, desired);
28
0
}
29
30
0
ZEND_API void zend_atomic_int_init(zend_atomic_int *obj, int desired) {
31
0
  ZEND_ATOMIC_INT_INIT(obj, desired);
32
0
}
33
34
0
ZEND_API bool zend_atomic_bool_exchange(zend_atomic_bool *obj, bool desired) {
35
0
  return zend_atomic_bool_exchange_ex(obj, desired);
36
0
}
37
38
0
ZEND_API int zend_atomic_int_exchange(zend_atomic_int *obj, int desired) {
39
0
  return zend_atomic_int_exchange_ex(obj, desired);
40
0
}
41
42
ZEND_API bool zend_atomic_bool_compare_exchange(zend_atomic_bool *obj, bool *expected, bool desired)
43
0
{
44
0
  return zend_atomic_bool_compare_exchange_ex(obj, expected, desired);
45
0
}
46
47
ZEND_API bool zend_atomic_int_compare_exchange(zend_atomic_int *obj, int *expected, int desired)
48
0
{
49
0
  return zend_atomic_int_compare_exchange_ex(obj, expected, desired);
50
0
}
51
52
0
ZEND_API void zend_atomic_bool_store(zend_atomic_bool *obj, bool desired) {
53
0
  zend_atomic_bool_store_ex(obj, desired);
54
0
}
55
56
0
ZEND_API void zend_atomic_int_store(zend_atomic_int *obj, int desired) {
57
0
  zend_atomic_int_store_ex(obj, desired);
58
0
}
59
60
#if defined(ZEND_WIN32) || defined(HAVE_SYNC_ATOMICS)
61
/* On these platforms it is non-const due to underlying APIs. */
62
ZEND_API bool zend_atomic_bool_load(zend_atomic_bool *obj) {
63
  return zend_atomic_bool_load_ex(obj);
64
}
65
ZEND_API int zend_atomic_int_load(zend_atomic_int *obj) {
66
  return zend_atomic_int_load_ex(obj);
67
}
68
#else
69
0
ZEND_API bool zend_atomic_bool_load(const zend_atomic_bool *obj) {
70
0
  return zend_atomic_bool_load_ex(obj);
71
0
}
72
0
ZEND_API int zend_atomic_int_load(const zend_atomic_int *obj) {
73
0
  return zend_atomic_int_load_ex(obj);
74
0
}
75
#endif