2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
7 * Userspace RCU header. Operations on pointers.
9 * TO BE INCLUDED ONLY IN CODE THAT IS TO BE RECOMPILED ON EACH LIBURCU
10 * RELEASE. See urcu.h for linking dynamically with the userspace rcu library.
13 #ifndef _LTTNG_UST_URCU_POINTER_STATIC_H
14 #define _LTTNG_UST_URCU_POINTER_STATIC_H
16 #include <urcu/compiler.h>
17 #include <urcu/arch.h>
18 #include <urcu/system.h>
19 #include <urcu/uatomic.h>
26 * _rcu_dereference - reads (copy) a RCU-protected pointer to a local variable
27 * into a RCU read-side critical section. The pointer can later be safely
28 * dereferenced within the critical section.
30 * This ensures that the pointer copy is invariant thorough the whole critical
33 * Inserts memory barriers on architectures that require them (currently only
34 * Alpha) and documents which pointers are protected by RCU.
36 * The compiler memory barrier in CMM_LOAD_SHARED() ensures that value-speculative
37 * optimizations (e.g. VSS: Value Speculation Scheduling) does not perform the
38 * data read before the pointer read by speculating the value of the pointer.
39 * Correct ordering is ensured because the pointer is read as a volatile access.
40 * This acts as a global side-effect operation, which forbids reordering of
41 * dependent memory operations. Note that such concern about dependency-breaking
42 * optimizations will eventually be taken care of by the "memory_order_consume"
43 * addition to forthcoming C++ standard.
45 * Should match rcu_assign_pointer() or rcu_xchg_pointer().
47 * This macro is less than 10 lines long. The intent is that this macro
48 * meets the 10-line criterion in LGPL, allowing this function to be
49 * expanded directly in non-LGPL code.
51 #define _lttng_ust_rcu_dereference(p) \
54 __typeof__(p) _________p1 = CMM_LOAD_SHARED(p); \
55 cmm_smp_read_barrier_depends(); \
60 * _rcu_cmpxchg_pointer - same as rcu_assign_pointer, but tests if the pointer
61 * is as expected by "old". If succeeds, returns the previous pointer to the
62 * data structure, which can be safely freed after waiting for a quiescent state
63 * using synchronize_rcu(). If fails (unexpected value), returns old (which
64 * should not be freed !).
66 * uatomic_cmpxchg() acts as both release and acquire barriers.
68 * This macro is less than 10 lines long. The intent is that this macro
69 * meets the 10-line criterion in LGPL, allowing this function to be
70 * expanded directly in non-LGPL code.
72 #define _lttng_ust_rcu_cmpxchg_pointer(p, old, _new) \
75 __typeof__(*p) _________pold = (old); \
76 __typeof__(*p) _________pnew = (_new); \
77 uatomic_cmpxchg(p, _________pold, _________pnew); \
81 * _rcu_xchg_pointer - same as rcu_assign_pointer, but returns the previous
82 * pointer to the data structure, which can be safely freed after waiting for a
83 * quiescent state using synchronize_rcu().
85 * uatomic_xchg() acts as both release and acquire barriers.
87 * This macro is less than 10 lines long. The intent is that this macro
88 * meets the 10-line criterion in LGPL, allowing this function to be
89 * expanded directly in non-LGPL code.
91 #define _lttng_ust_rcu_xchg_pointer(p, v) \
94 __typeof__(*p) _________pv = (v); \
95 uatomic_xchg(p, _________pv); \
99 #define _lttng_ust_rcu_set_pointer(p, v) \
101 __typeof__(*p) _________pv = (v); \
102 if (!__builtin_constant_p(v) || \
105 uatomic_set(p, _________pv); \
109 * _rcu_assign_pointer - assign (publicize) a pointer to a new data structure
110 * meant to be read by RCU read-side critical sections. Returns the assigned
113 * Documents which pointers will be dereferenced by RCU read-side critical
114 * sections and adds the required memory barriers on architectures requiring
115 * them. It also makes sure the compiler does not reorder code initializing the
116 * data structure before its publication.
118 * Should match rcu_dereference().
120 * This macro is less than 10 lines long. The intent is that this macro
121 * meets the 10-line criterion in LGPL, allowing this function to be
122 * expanded directly in non-LGPL code.
124 #define _lttng_ust_rcu_assign_pointer(p, v) _lttng_ust_rcu_set_pointer(&(p), v)
130 #endif /* _LTTNG_UST_URCU_POINTER_STATIC_H */
This page took 0.045259 seconds and 4 git commands to generate.