uatomic compat: complete i386 support
[urcu.git] / urcu-pointer.h
CommitLineData
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 *
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>
48d848c7 31#include <urcu/uatomic_arch.h>
7e30abe3
MD
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
7e30abe3
MD
61#else /* !_LGPL_SOURCE */
62
2ff1db4a
MD
63extern void *rcu_dereference_sym(void *p);
64#define rcu_dereference(p) \
65 ({ \
66 typeof(p) _________p1 = \
67 rcu_dereference_sym((void *)(p)); \
68 (_________p1); \
69 })
7e30abe3
MD
70
71extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
2ff1db4a
MD
72#define rcu_cmpxchg_pointer(p, old, _new) \
73 ({ \
2b5554c9
MD
74 typeof(*p) _________pold = (old); \
75 typeof(*p) _________pnew = (_new); \
2ff1db4a 76 typeof(*p) _________p1 = \
2b5554c9
MD
77 rcu_cmpxchg_pointer_sym((void **)(p), _________pold, \
78 _________pnew); \
2ff1db4a
MD
79 (_________p1); \
80 })
7e30abe3
MD
81
82extern void *rcu_xchg_pointer_sym(void **p, void *v);
2ff1db4a
MD
83#define rcu_xchg_pointer(p, v) \
84 ({ \
2b5554c9 85 typeof(*p) _________pv = (v); \
2ff1db4a 86 typeof(*p) _________p1 = \
2b5554c9 87 rcu_xchg_pointer_sym((void **)(p), _________pv); \
2ff1db4a
MD
88 (_________p1); \
89 })
7e30abe3
MD
90
91extern void *rcu_set_pointer_sym(void **p, void *v);
2ff1db4a
MD
92#define rcu_set_pointer(p, v) \
93 ({ \
2b5554c9 94 typeof(*p) _________pv = (v); \
2ff1db4a 95 typeof(*p) _________p1 = \
2b5554c9 96 rcu_set_pointer_sym((void **)(p), _________pv); \
2ff1db4a 97 })
7e30abe3
MD
98
99#endif /* !_LGPL_SOURCE */
100
101/*
102 * rcu_assign_pointer(type *ptr, type *new)
103 *
104 * Same as rcu_set_pointer, but takes the pointer to assign to rather than its
105 * address as first parameter. Provided for compatibility with the Linux kernel
106 * RCU semantic.
107 */
108#define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
109
110#endif /* _URCU_POINTER_H */
This page took 0.026279 seconds and 4 git commands to generate.