Fix: memory leak in urcu-checker
[userspace-rcu.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 *
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>
791151d0 32#include <urcu/urcu-checker.h>
7e30abe3 33
36bc70a8
MD
34#ifdef __cplusplus
35extern "C" {
36#endif
37
d663f489 38#if defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)
7e30abe3 39
af7c2dbe 40#include <urcu/static/urcu-pointer.h>
7e30abe3
MD
41
42/*
43 * rcu_dereference(ptr)
44 *
45 * Fetch a RCU-protected pointer. Typically used to copy the variable ptr to a
46 * local variable.
47 */
791151d0
MD
48#define rcu_dereference(p) \
49 ({ \
50 rcu_read_ongoing_check_debug(__func__); \
51 _rcu_dereference(p); \
52 })
7e30abe3
MD
53
54/*
3daae22a 55 * type *rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
7e30abe3 56 * type *rcu_xchg_pointer(type **ptr, type *new)
3daae22a 57 * void rcu_set_pointer(type **ptr, type *new)
7e30abe3
MD
58 *
59 * RCU pointer updates.
60 * @ptr: address of the pointer to modify
61 * @new: new pointer value
62 * @old: old pointer value (expected)
63 *
64 * return: old pointer value
65 */
66#define rcu_cmpxchg_pointer _rcu_cmpxchg_pointer
67#define rcu_xchg_pointer _rcu_xchg_pointer
68#define rcu_set_pointer _rcu_set_pointer
69
d663f489 70#else /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
7e30abe3 71
2ff1db4a
MD
72extern void *rcu_dereference_sym(void *p);
73#define rcu_dereference(p) \
74 ({ \
bdffa73a 75 __typeof__(p) _________p1 = URCU_FORCE_CAST(__typeof__(p), \
4501f284 76 rcu_dereference_sym(URCU_FORCE_CAST(void *, p))); \
2ff1db4a
MD
77 (_________p1); \
78 })
7e30abe3
MD
79
80extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
2ff1db4a
MD
81#define rcu_cmpxchg_pointer(p, old, _new) \
82 ({ \
bdffa73a
MD
83 __typeof__(*(p)) _________pold = (old); \
84 __typeof__(*(p)) _________pnew = (_new); \
85 __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
86 rcu_cmpxchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
4501f284
MD
87 _________pold, \
88 _________pnew)); \
2ff1db4a
MD
89 (_________p1); \
90 })
7e30abe3
MD
91
92extern void *rcu_xchg_pointer_sym(void **p, void *v);
2ff1db4a
MD
93#define rcu_xchg_pointer(p, v) \
94 ({ \
bdffa73a
MD
95 __typeof__(*(p)) _________pv = (v); \
96 __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
4501f284
MD
97 rcu_xchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
98 _________pv)); \
2ff1db4a
MD
99 (_________p1); \
100 })
7e30abe3 101
3daae22a
MD
102/*
103 * Note: rcu_set_pointer_sym returns @v because we don't want to break
104 * the ABI. At the API level, rcu_set_pointer() now returns void. Use of
105 * the return value is therefore deprecated, and will cause a build
106 * error.
107 */
7e30abe3 108extern void *rcu_set_pointer_sym(void **p, void *v);
2ff1db4a 109#define rcu_set_pointer(p, v) \
3daae22a 110 do { \
bdffa73a 111 __typeof__(*(p)) _________pv = (v); \
3daae22a
MD
112 (void) rcu_set_pointer_sym(URCU_FORCE_CAST(void **, p), \
113 _________pv); \
114 } while (0)
7e30abe3 115
d663f489 116#endif /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
7e30abe3
MD
117
118/*
3daae22a 119 * void rcu_assign_pointer(type *ptr, type *new)
7e30abe3
MD
120 *
121 * Same as rcu_set_pointer, but takes the pointer to assign to rather than its
122 * address as first parameter. Provided for compatibility with the Linux kernel
123 * RCU semantic.
124 */
125#define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
126
36bc70a8
MD
127#ifdef __cplusplus
128}
129#endif
130
7e30abe3 131#endif /* _URCU_POINTER_H */
This page took 0.033364 seconds and 4 git commands to generate.