| 1 | #ifndef _URCU_BP_H |
| 2 | #define _URCU_BP_H |
| 3 | |
| 4 | /* |
| 5 | * urcu-bp.h |
| 6 | * |
| 7 | * Userspace RCU header, "bulletproof" version. |
| 8 | * |
| 9 | * Slower RCU read-side adapted for tracing library. Does not require thread |
| 10 | * registration nor unregistration. Also signal-safe. |
| 11 | * |
| 12 | * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 13 | * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. |
| 14 | * |
| 15 | * LGPL-compatible code should include this header with : |
| 16 | * |
| 17 | * #define _LGPL_SOURCE |
| 18 | * #include <urcu.h> |
| 19 | * |
| 20 | * This library is free software; you can redistribute it and/or |
| 21 | * modify it under the terms of the GNU Lesser General Public |
| 22 | * License as published by the Free Software Foundation; either |
| 23 | * version 2.1 of the License, or (at your option) any later version. |
| 24 | * |
| 25 | * This library is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 28 | * Lesser General Public License for more details. |
| 29 | * |
| 30 | * You should have received a copy of the GNU Lesser General Public |
| 31 | * License along with this library; if not, write to the Free Software |
| 32 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 33 | * |
| 34 | * IBM's contributions to this file may be relicensed under LGPLv2 or later. |
| 35 | */ |
| 36 | |
| 37 | #include <stdlib.h> |
| 38 | #include <pthread.h> |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | #include <urcu/map/urcu-bp.h> |
| 45 | |
| 46 | /* |
| 47 | * Important ! |
| 48 | * |
| 49 | * Each thread containing read-side critical sections must be registered |
| 50 | * with rcu_register_thread() before calling rcu_read_lock(). |
| 51 | * rcu_unregister_thread() should be called before the thread exits. |
| 52 | */ |
| 53 | |
| 54 | /* |
| 55 | * See urcu-pointer.h and urcu/static/urcu-pointer.h for pointer |
| 56 | * publication headers. |
| 57 | */ |
| 58 | #include <urcu-pointer.h> |
| 59 | |
| 60 | #ifdef _LGPL_SOURCE |
| 61 | |
| 62 | #include <urcu/static/urcu-bp.h> |
| 63 | |
| 64 | /* |
| 65 | * Mappings for static use of the userspace RCU library. |
| 66 | * Should only be used in LGPL-compatible code. |
| 67 | */ |
| 68 | |
| 69 | /* |
| 70 | * rcu_read_lock() |
| 71 | * rcu_read_unlock() |
| 72 | * |
| 73 | * Mark the beginning and end of a read-side critical section. |
| 74 | */ |
| 75 | #define rcu_read_lock_bp _rcu_read_lock |
| 76 | #define rcu_read_unlock_bp _rcu_read_unlock |
| 77 | #define rcu_read_ongoing_bp _rcu_read_ongoing |
| 78 | |
| 79 | #define rcu_dereference_bp rcu_dereference |
| 80 | #define rcu_cmpxchg_pointer_bp rcu_cmpxchg_pointer |
| 81 | #define rcu_xchg_pointer_bp rcu_xchg_pointer |
| 82 | #define rcu_set_pointer_bp rcu_set_pointer |
| 83 | |
| 84 | #else /* !_LGPL_SOURCE */ |
| 85 | |
| 86 | /* |
| 87 | * library wrappers to be used by non-LGPL compatible source code. |
| 88 | * See LGPL-only urcu/static/urcu-pointer.h for documentation. |
| 89 | */ |
| 90 | |
| 91 | extern void rcu_read_lock(void); |
| 92 | extern void rcu_read_unlock(void); |
| 93 | extern int rcu_read_ongoing(void); |
| 94 | |
| 95 | extern void *rcu_dereference_sym_bp(void *p); |
| 96 | #define rcu_dereference_bp(p) \ |
| 97 | ({ \ |
| 98 | __typeof__(p) _________p1 = URCU_FORCE_CAST(__typeof__(p), \ |
| 99 | rcu_dereference_sym_bp(URCU_FORCE_CAST(void *, p))); \ |
| 100 | (_________p1); \ |
| 101 | }) |
| 102 | |
| 103 | extern void *rcu_cmpxchg_pointer_sym_bp(void **p, void *old, void *_new); |
| 104 | #define rcu_cmpxchg_pointer_bp(p, old, _new) \ |
| 105 | ({ \ |
| 106 | __typeof__(*(p)) _________pold = (old); \ |
| 107 | __typeof__(*(p)) _________pnew = (_new); \ |
| 108 | __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \ |
| 109 | rcu_cmpxchg_pointer_sym_bp(URCU_FORCE_CAST(void **, p), \ |
| 110 | _________pold, \ |
| 111 | _________pnew)); \ |
| 112 | (_________p1); \ |
| 113 | }) |
| 114 | |
| 115 | extern void *rcu_xchg_pointer_sym_bp(void **p, void *v); |
| 116 | #define rcu_xchg_pointer_bp(p, v) \ |
| 117 | ({ \ |
| 118 | __typeof__(*(p)) _________pv = (v); \ |
| 119 | __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)),\ |
| 120 | rcu_xchg_pointer_sym_bp(URCU_FORCE_CAST(void **, p), \ |
| 121 | _________pv)); \ |
| 122 | (_________p1); \ |
| 123 | }) |
| 124 | |
| 125 | extern void *rcu_set_pointer_sym_bp(void **p, void *v); |
| 126 | #define rcu_set_pointer_bp(p, v) \ |
| 127 | ({ \ |
| 128 | __typeof__(*(p)) _________pv = (v); \ |
| 129 | __typeof__(*(p)) _________p1 = URCU_FORCE_CAST(__typeof__(*(p)), \ |
| 130 | rcu_set_pointer_sym_bp(URCU_FORCE_CAST(void **, p), \ |
| 131 | _________pv)); \ |
| 132 | (_________p1); \ |
| 133 | }) |
| 134 | |
| 135 | #endif /* !_LGPL_SOURCE */ |
| 136 | |
| 137 | extern void synchronize_rcu(void); |
| 138 | |
| 139 | /* |
| 140 | * rcu_bp_before_fork, rcu_bp_after_fork_parent and rcu_bp_after_fork_child |
| 141 | * should be called around fork() system calls when the child process is not |
| 142 | * expected to immediately perform an exec(). For pthread users, see |
| 143 | * pthread_atfork(3). |
| 144 | */ |
| 145 | extern void rcu_bp_before_fork(void); |
| 146 | extern void rcu_bp_after_fork_parent(void); |
| 147 | extern void rcu_bp_after_fork_child(void); |
| 148 | |
| 149 | /* |
| 150 | * In the bulletproof version, the following functions are no-ops. |
| 151 | */ |
| 152 | static inline void rcu_register_thread(void) |
| 153 | { |
| 154 | } |
| 155 | |
| 156 | static inline void rcu_unregister_thread(void) |
| 157 | { |
| 158 | } |
| 159 | |
| 160 | static inline void rcu_init(void) |
| 161 | { |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Q.S. reporting are no-ops for these URCU flavors. |
| 166 | */ |
| 167 | static inline void rcu_quiescent_state(void) |
| 168 | { |
| 169 | } |
| 170 | |
| 171 | static inline void rcu_thread_offline(void) |
| 172 | { |
| 173 | } |
| 174 | |
| 175 | static inline void rcu_thread_online(void) |
| 176 | { |
| 177 | } |
| 178 | |
| 179 | #ifdef __cplusplus |
| 180 | } |
| 181 | #endif |
| 182 | |
| 183 | #include <urcu-call-rcu.h> |
| 184 | #include <urcu-defer.h> |
| 185 | #include <urcu-flavor.h> |
| 186 | |
| 187 | #endif /* _URCU_BP_H */ |