1 #ifndef _URCU_POINTER_STATIC_H
2 #define _URCU_POINTER_STATIC_H
5 * urcu/static/pointer.h
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.
12 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * IBM's contributions to this file may be relicensed under LGPLv2 or later.
32 #include <urcu/compiler.h>
33 #include <urcu/arch.h>
34 #include <urcu/system.h>
35 #include <urcu/uatomic.h>
42 * _rcu_dereference - reads (copy) a RCU-protected pointer to a local variable
43 * into a RCU read-side critical section. The pointer can later be safely
44 * dereferenced within the critical section.
46 * This ensures that the pointer copy is invariant thorough the whole critical
49 * Inserts memory barriers on architectures that require them (currently only
50 * Alpha) and documents which pointers are protected by RCU.
52 * The compiler memory barrier in CMM_LOAD_SHARED() ensures that value-speculative
53 * optimizations (e.g. VSS: Value Speculation Scheduling) does not perform the
54 * data read before the pointer read by speculating the value of the pointer.
55 * Correct ordering is ensured because the pointer is read as a volatile access.
56 * This acts as a global side-effect operation, which forbids reordering of
57 * dependent memory operations. Note that such concern about dependency-breaking
58 * optimizations will eventually be taken care of by the "memory_order_consume"
59 * addition to forthcoming C++ standard.
61 * Should match rcu_assign_pointer() or rcu_xchg_pointer().
63 * This macro is less than 10 lines long. The intent is that this macro
64 * meets the 10-line criterion in LGPL, allowing this function to be
65 * expanded directly in non-LGPL code.
67 #define _rcu_dereference(p) \
70 __typeof__(p) _________p1 = CMM_LOAD_SHARED(p); \
71 cmm_smp_read_barrier_depends(); \
76 * _rcu_cmpxchg_pointer - same as rcu_assign_pointer, but tests if the pointer
77 * is as expected by "old". If succeeds, returns the previous pointer to the
78 * data structure, which can be safely freed after waiting for a quiescent state
79 * using synchronize_rcu(). If fails (unexpected value), returns old (which
80 * should not be freed !).
82 * uatomic_cmpxchg() acts as both release and acquire barriers.
84 * This macro is less than 10 lines long. The intent is that this macro
85 * meets the 10-line criterion in LGPL, allowing this function to be
86 * expanded directly in non-LGPL code.
88 #define _rcu_cmpxchg_pointer(p, old, _new) \
91 __typeof__(*p) _________pold = (old); \
92 __typeof__(*p) _________pnew = (_new); \
93 uatomic_cmpxchg(p, _________pold, _________pnew); \
97 * _rcu_xchg_pointer - same as rcu_assign_pointer, but returns the previous
98 * pointer to the data structure, which can be safely freed after waiting for a
99 * quiescent state using synchronize_rcu().
101 * uatomic_xchg() acts as both release and acquire barriers.
103 * This macro is less than 10 lines long. The intent is that this macro
104 * meets the 10-line criterion in LGPL, allowing this function to be
105 * expanded directly in non-LGPL code.
107 #define _rcu_xchg_pointer(p, v) \
110 __typeof__(*p) _________pv = (v); \
111 uatomic_xchg(p, _________pv); \
115 #define _rcu_set_pointer(p, v) \
117 __typeof__(*p) _________pv = (v); \
118 if (!__builtin_constant_p(v) || \
121 uatomic_set(p, _________pv); \
125 * _rcu_assign_pointer - assign (publicize) a pointer to a new data structure
126 * meant to be read by RCU read-side critical sections. Returns the assigned
129 * Documents which pointers will be dereferenced by RCU read-side critical
130 * sections and adds the required memory barriers on architectures requiring
131 * them. It also makes sure the compiler does not reorder code initializing the
132 * data structure before its publication.
134 * Should match rcu_dereference().
136 * This macro is less than 10 lines long. The intent is that this macro
137 * meets the 10-line criterion in LGPL, allowing this function to be
138 * expanded directly in non-LGPL code.
140 #define _rcu_assign_pointer(p, v) _rcu_set_pointer(&(p), v)
146 #endif /* _URCU_POINTER_STATIC_H */
This page took 0.038679 seconds and 4 git commands to generate.