Commit | Line | Data |
---|---|---|
7e30abe3 MD |
1 | #ifndef _URCU_POINTER_H |
2 | #define _URCU_POINTER_H | |
3 | ||
4 | /* | |
5 | * urcu-pointer.h | |
6 | * | |
7 | * Userspace RCU header. Operations on pointers. | |
8 | * | |
6982d6d7 | 9 | * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
7e30abe3 MD |
10 | * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. |
11 | * | |
12 | * This library is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public | |
14 | * License as published by the Free Software Foundation; either | |
15 | * version 2.1 of the License, or (at your option) any later version. | |
16 | * | |
17 | * This library is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * Lesser General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this library; if not, write to the Free Software | |
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
25 | * | |
26 | * IBM's contributions to this file may be relicensed under LGPLv2 or later. | |
27 | */ | |
28 | ||
29 | #include <urcu/compiler.h> | |
30 | #include <urcu/arch.h> | |
a2e7bf9c | 31 | #include <urcu/uatomic.h> |
7e30abe3 | 32 | |
36bc70a8 MD |
33 | #ifdef __cplusplus |
34 | extern "C" { | |
35 | #endif | |
36 | ||
7e30abe3 MD |
37 | #ifdef _LGPL_SOURCE |
38 | ||
af7c2dbe | 39 | #include <urcu/static/urcu-pointer.h> |
7e30abe3 MD |
40 | |
41 | /* | |
42 | * rcu_dereference(ptr) | |
43 | * | |
44 | * Fetch a RCU-protected pointer. Typically used to copy the variable ptr to a | |
45 | * local variable. | |
46 | */ | |
47 | #define rcu_dereference _rcu_dereference | |
48 | ||
49 | /* | |
50 | * rcu_cmpxchg_pointer(type **ptr, type *new, type *old) | |
51 | * type *rcu_xchg_pointer(type **ptr, type *new) | |
52 | * type *rcu_set_pointer(type **ptr, type *new) | |
53 | * | |
54 | * RCU pointer updates. | |
55 | * @ptr: address of the pointer to modify | |
56 | * @new: new pointer value | |
57 | * @old: old pointer value (expected) | |
58 | * | |
59 | * return: old pointer value | |
60 | */ | |
61 | #define rcu_cmpxchg_pointer _rcu_cmpxchg_pointer | |
62 | #define rcu_xchg_pointer _rcu_xchg_pointer | |
63 | #define rcu_set_pointer _rcu_set_pointer | |
64 | ||
7e30abe3 MD |
65 | #else /* !_LGPL_SOURCE */ |
66 | ||
2ff1db4a MD |
67 | extern void *rcu_dereference_sym(void *p); |
68 | #define rcu_dereference(p) \ | |
69 | ({ \ | |
4501f284 MD |
70 | typeof(p) _________p1 = URCU_FORCE_CAST(typeof(p), \ |
71 | rcu_dereference_sym(URCU_FORCE_CAST(void *, p))); \ | |
2ff1db4a MD |
72 | (_________p1); \ |
73 | }) | |
7e30abe3 MD |
74 | |
75 | extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new); | |
2ff1db4a MD |
76 | #define rcu_cmpxchg_pointer(p, old, _new) \ |
77 | ({ \ | |
4501f284 MD |
78 | typeof(*(p)) _________pold = (old); \ |
79 | typeof(*(p)) _________pnew = (_new); \ | |
80 | typeof(*(p)) _________p1 = URCU_FORCE_CAST(typeof(*(p)), \ | |
81 | rcu_cmpxchg_pointer_sym(URCU_FORCE_CAST(void **, p),\ | |
82 | _________pold, \ | |
83 | _________pnew)); \ | |
2ff1db4a MD |
84 | (_________p1); \ |
85 | }) | |
7e30abe3 MD |
86 | |
87 | extern void *rcu_xchg_pointer_sym(void **p, void *v); | |
2ff1db4a MD |
88 | #define rcu_xchg_pointer(p, v) \ |
89 | ({ \ | |
4501f284 MD |
90 | typeof(*(p)) _________pv = (v); \ |
91 | typeof(*(p)) _________p1 = URCU_FORCE_CAST(typeof(*(p)), \ | |
92 | rcu_xchg_pointer_sym(URCU_FORCE_CAST(void **, p), \ | |
93 | _________pv)); \ | |
2ff1db4a MD |
94 | (_________p1); \ |
95 | }) | |
7e30abe3 MD |
96 | |
97 | extern void *rcu_set_pointer_sym(void **p, void *v); | |
2ff1db4a MD |
98 | #define rcu_set_pointer(p, v) \ |
99 | ({ \ | |
4501f284 MD |
100 | typeof(*(p)) _________pv = (v); \ |
101 | typeof(*(p)) _________p1 = URCU_FORCE_CAST(typeof(*(p)), \ | |
102 | rcu_set_pointer_sym(URCU_FORCE_CAST(void **, p), \ | |
103 | _________pv)); \ | |
8b7bebb1 | 104 | (_________p1); \ |
2ff1db4a | 105 | }) |
7e30abe3 MD |
106 | |
107 | #endif /* !_LGPL_SOURCE */ | |
108 | ||
109 | /* | |
110 | * rcu_assign_pointer(type *ptr, type *new) | |
111 | * | |
112 | * Same as rcu_set_pointer, but takes the pointer to assign to rather than its | |
113 | * address as first parameter. Provided for compatibility with the Linux kernel | |
114 | * RCU semantic. | |
115 | */ | |
116 | #define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v)) | |
117 | ||
36bc70a8 MD |
118 | #ifdef __cplusplus |
119 | } | |
120 | #endif | |
121 | ||
7e30abe3 | 122 | #endif /* _URCU_POINTER_H */ |