139c37f6d474a646141bb0650b6f8c936061a9a2
[urcu.git] / include / urcu / system.h
1 // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 //
3 // SPDX-License-Identifier: MIT
4
5 #ifndef _URCU_SYSTEM_H
6 #define _URCU_SYSTEM_H
7
8 /*
9 * System definitions.
10 */
11
12 #include <urcu/config.h>
13 #include <urcu/compiler.h>
14 #include <urcu/arch.h>
15
16 #ifdef CONFIG_RCU_USE_ATOMIC_BUILTINS
17
18 #define CMM_LOAD_SHARED(x) \
19 __atomic_load_n(cmm_cast_volatile(&(x)), __ATOMIC_RELAXED)
20
21 #define _CMM_LOAD_SHARED(x) CMM_LOAD_SHARED(x)
22
23 #define CMM_STORE_SHARED(x, v) \
24 __extension__ \
25 ({ \
26 __typeof__(v) _v = (v); \
27 __atomic_store_n(cmm_cast_volatile(&(x)), _v, \
28 __ATOMIC_RELAXED); \
29 _v; \
30 })
31
32 #define _CMM_STORE_SHARED(x, v) CMM_STORE_SHARED(x, v)
33
34 #else
35 /*
36 * Identify a shared load. A cmm_smp_rmc() or cmm_smp_mc() should come
37 * before the load.
38 */
39 #define _CMM_LOAD_SHARED(p) CMM_ACCESS_ONCE(p)
40
41 /*
42 * Load a data from shared memory, doing a cache flush if required.
43 */
44 #define CMM_LOAD_SHARED(p) \
45 __extension__ \
46 ({ \
47 cmm_smp_rmc(); \
48 _CMM_LOAD_SHARED(p); \
49 })
50
51 /*
52 * Identify a shared store. A cmm_smp_wmc() or cmm_smp_mc() should
53 * follow the store.
54 */
55 #define _CMM_STORE_SHARED(x, v) __extension__ ({ CMM_ACCESS_ONCE(x) = (v); })
56
57 /*
58 * Store v into x, where x is located in shared memory. Performs the
59 * required cache flush after writing. Returns v.
60 */
61 #define CMM_STORE_SHARED(x, v) \
62 __extension__ \
63 ({ \
64 __typeof__(x) _v = _CMM_STORE_SHARED(x, v); \
65 cmm_smp_wmc(); \
66 _v = _v; /* Work around clang "unused result" */ \
67 })
68
69 #endif /* CONFIG_RCU_USE_ATOMIC_BUILTINS */
70
71 #endif /* _URCU_SYSTEM_H */
This page took 0.033132 seconds and 5 git commands to generate.