Fix: handle sys_futex() FUTEX_WAIT interrupted by signal
[urcu.git] / urcu-pointer.h
... / ...
CommitLineData
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@efficios.com>
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/uatomic.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#if defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)
38
39#include <urcu/static/urcu-pointer.h>
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 * type *rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
51 * type *rcu_xchg_pointer(type **ptr, type *new)
52 * void 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
65#else /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
66
67extern void *rcu_dereference_sym(void *p);
68#define rcu_dereference(p) \
69 __extension__ \
70 ({ \
71 __typeof__(p) _________p1 = URCU_FORCE_CAST(__typeof__(p), \
72 rcu_dereference_sym(URCU_FORCE_CAST(void *, p))); \
73 (_________p1); \
74 })
75
76extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
77#define rcu_cmpxchg_pointer(p, old, _new) \
78 __extension__ \
79 ({ \
80 __typeof__(*(p)) _________pold = (old); \
81 __typeof__(*(p)) _________pnew = (_new); \
82 __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
83 rcu_cmpxchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
84 _________pold, \
85 _________pnew)); \
86 (_________p1); \
87 })
88
89extern void *rcu_xchg_pointer_sym(void **p, void *v);
90#define rcu_xchg_pointer(p, v) \
91 __extension__ \
92 ({ \
93 __typeof__(*(p)) _________pv = (v); \
94 __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
95 rcu_xchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
96 _________pv)); \
97 (_________p1); \
98 })
99
100/*
101 * Note: rcu_set_pointer_sym returns @v because we don't want to break
102 * the ABI. At the API level, rcu_set_pointer() now returns void. Use of
103 * the return value is therefore deprecated, and will cause a build
104 * error.
105 */
106extern void *rcu_set_pointer_sym(void **p, void *v);
107#define rcu_set_pointer(p, v) \
108 do { \
109 __typeof__(*(p)) _________pv = (v); \
110 (void) rcu_set_pointer_sym(URCU_FORCE_CAST(void **, p), \
111 _________pv); \
112 } while (0)
113
114#endif /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
115
116/*
117 * void rcu_assign_pointer(type *ptr, type *new)
118 *
119 * Same as rcu_set_pointer, but takes the pointer to assign to rather than its
120 * address as first parameter. Provided for compatibility with the Linux kernel
121 * RCU semantic.
122 */
123#define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* _URCU_POINTER_H */
This page took 0.021923 seconds and 4 git commands to generate.