forked from urcu/userspace-rcu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
urcu-pointer.h
129 lines (113 loc) · 4.03 KB
/
urcu-pointer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef _URCU_POINTER_H
#define _URCU_POINTER_H
/*
* urcu-pointer.h
*
* Userspace RCU header. Operations on pointers.
*
* Copyright (c) 2009 Mathieu Desnoyers <[email protected]>
* Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* IBM's contributions to this file may be relicensed under LGPLv2 or later.
*/
#include <urcu/compiler.h>
#include <urcu/arch.h>
#include <urcu/uatomic.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)
#include <urcu/static/urcu-pointer.h>
/*
* rcu_dereference(ptr)
*
* Fetch a RCU-protected pointer. Typically used to copy the variable ptr to a
* local variable.
*/
#define rcu_dereference _rcu_dereference
/*
* type *rcu_cmpxchg_pointer(type **ptr, type *new, type *old)
* type *rcu_xchg_pointer(type **ptr, type *new)
* void rcu_set_pointer(type **ptr, type *new)
*
* RCU pointer updates.
* @ptr: address of the pointer to modify
* @new: new pointer value
* @old: old pointer value (expected)
*
* return: old pointer value
*/
#define rcu_cmpxchg_pointer _rcu_cmpxchg_pointer
#define rcu_xchg_pointer _rcu_xchg_pointer
#define rcu_set_pointer _rcu_set_pointer
#else /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
extern void *rcu_dereference_sym(void *p);
#define rcu_dereference(p) \
__extension__ \
({ \
__typeof__(p) _________p1 = URCU_FORCE_CAST(__typeof__(p), \
rcu_dereference_sym(URCU_FORCE_CAST(void *, p))); \
(_________p1); \
})
extern void *rcu_cmpxchg_pointer_sym(void **p, void *old, void *_new);
#define rcu_cmpxchg_pointer(p, old, _new) \
__extension__ \
({ \
__typeof__(*(p)) _________pold = (old); \
__typeof__(*(p)) _________pnew = (_new); \
__typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
rcu_cmpxchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
_________pold, \
_________pnew)); \
(_________p1); \
})
extern void *rcu_xchg_pointer_sym(void **p, void *v);
#define rcu_xchg_pointer(p, v) \
__extension__ \
({ \
__typeof__(*(p)) _________pv = (v); \
__typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \
rcu_xchg_pointer_sym(URCU_FORCE_CAST(void **, p), \
_________pv)); \
(_________p1); \
})
/*
* Note: rcu_set_pointer_sym returns @v because we don't want to break
* the ABI. At the API level, rcu_set_pointer() now returns void. Use of
* the return value is therefore deprecated, and will cause a build
* error.
*/
extern void *rcu_set_pointer_sym(void **p, void *v);
#define rcu_set_pointer(p, v) \
do { \
__typeof__(*(p)) _________pv = (v); \
(void) rcu_set_pointer_sym(URCU_FORCE_CAST(void **, p), \
_________pv); \
} while (0)
#endif /* !(defined(_LGPL_SOURCE) || defined(URCU_INLINE_SMALL_FUNCTIONS)) */
/*
* void rcu_assign_pointer(type *ptr, type *new)
*
* Same as rcu_set_pointer, but takes the pointer to assign to rather than its
* address as first parameter. Provided for compatibility with the Linux kernel
* RCU semantic.
*/
#define rcu_assign_pointer(p, v) rcu_set_pointer((&p), (v))
#ifdef __cplusplus
}
#endif
#endif /* _URCU_POINTER_H */