748a37a0e7fe3e2f7d493a7b0276602ef1efbc99
[urcu.git] / urcu-pointer.h
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 *
9 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
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>
31 #include <urcu/arch_uatomic.h>
32
33 #ifdef _LGPL_SOURCE
34
35 #include <urcu-pointer-static.h>
36
37 /*
38 * rcu_dereference(ptr)
39 *
40 * Fetch a RCU-protected pointer. Typically used to copy the variable ptr to a
41 * local variable.
42 */
43 #define rcu_dereference _rcu_dereference
44
45 /*
46 * rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
47 * type *rcu_xchg_pointer(type **ptr, type *new)
48 * type *rcu_set_pointer(type **ptr, type *new)
49 *
50 * RCU pointer updates.
51 * @ptr: address of the pointer to modify
52 * @new: new pointer value
53 * @old: old pointer value (expected)
54 *
55 * return: old pointer value
56 */
57 #define rcu_cmpxchg_pointer _rcu_cmpxchg_pointer
58 #define rcu_xchg_pointer _rcu_xchg_pointer
59 #define rcu_set_pointer _rcu_set_pointer
60
61 /*
62 * type *rcu_publish_content(type **ptr, type *new)
63 *
64 * Exchanges the pointer and waits for quiescent state. The pointer returned
65 * can be freed. You are encouraged to use either
66 * - rcu_cmpxchg_pointer
67 * - rcu_xchg_pointer
68 * - rcu_set_pointer
69 * with call_rcu(free, ptr) instead to deal with reclamation more efficiently.
70 */
71 #define rcu_publish_content _rcu_publish_content
72
73 #else /* !_LGPL_SOURCE */
74
75 extern void *rcu_dereference(void *p);
76
77 extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
78 #define rcu_cmpxchg_pointer(p, old, _new) \
79 rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new))
80
81 extern void *rcu_xchg_pointer_sym(void **p, void *v);
82 #define rcu_xchg_pointer(p, v) \
83 rcu_xchg_pointer_sym((void **)(p), (v))
84
85 extern void *rcu_set_pointer_sym(void **p, void *v);
86 #define rcu_set_pointer(p, v) \
87 rcu_set_pointer_sym((void **)(p), (v))
88
89 extern void *rcu_publish_content_sym(void **p, void *v);
90 #define rcu_publish_content(p, v) \
91 rcu_publish_content_sym((void **)(p), (v))
92
93 extern void *rcu_assign_pointer_sym(void **p, void *v);
94
95 #endif /* !_LGPL_SOURCE */
96
97 /*
98 * rcu_assign_pointer(type *ptr, type *new)
99 *
100 * Same as rcu_set_pointer, but takes the pointer to assign to rather than its
101 * address as first parameter. Provided for compatibility with the Linux kernel
102 * RCU semantic.
103 */
104 #define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
105
106 #endif /* _URCU_POINTER_H */
This page took 0.043051 seconds and 3 git commands to generate.