Add type checking in urcu-pointer.h macros
[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>
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
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 ({ \
74 typeof(*p) _________p1 = \
75 rcu_cmpxchg_pointer_sym((void **)(p), (old), (_new));\
76 (_________p1); \
77 })
7e30abe3
MD
78
79extern void *rcu_xchg_pointer_sym(void **p, void *v);
2ff1db4a
MD
80#define rcu_xchg_pointer(p, v) \
81 ({ \
82 typeof(*p) _________p1 = \
83 rcu_xchg_pointer_sym((void **)(p), (v)); \
84 (_________p1); \
85 })
7e30abe3
MD
86
87extern void *rcu_set_pointer_sym(void **p, void *v);
2ff1db4a
MD
88#define rcu_set_pointer(p, v) \
89 ({ \
90 typeof(*p) _________p1 = \
91 rcu_set_pointer_sym((void **)(p), (v)); \
92 })
7e30abe3
MD
93
94#endif /* !_LGPL_SOURCE */
95
96/*
97 * rcu_assign_pointer(type *ptr, type *new)
98 *
99 * Same as rcu_set_pointer, but takes the pointer to assign to rather than its
100 * address as first parameter. Provided for compatibility with the Linux kernel
101 * RCU semantic.
102 */
103#define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
104
105#endif /* _URCU_POINTER_H */
This page took 0.026633 seconds and 4 git commands to generate.