Commit | Line | Data |
---|---|---|
9f1621ca | 1 | /* |
7ac06cef | 2 | * urcu-qsbr.c |
9f1621ca | 3 | * |
7ac06cef | 4 | * Userspace RCU QSBR library |
9f1621ca | 5 | * |
6982d6d7 | 6 | * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
9f1621ca MD |
7 | * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. |
8 | * | |
9 | * This library is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License as published by the Free Software Foundation; either | |
12 | * version 2.1 of the License, or (at your option) any later version. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * Lesser General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Lesser General Public | |
20 | * License along with this library; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 | * | |
23 | * IBM's contributions to this file may be relicensed under LGPLv2 or later. | |
24 | */ | |
25 | ||
e37faee1 | 26 | #define URCU_NO_COMPAT_IDENTIFIERS |
71c811bf | 27 | #define _LGPL_SOURCE |
9f1621ca MD |
28 | #include <stdio.h> |
29 | #include <pthread.h> | |
30 | #include <signal.h> | |
31 | #include <assert.h> | |
32 | #include <stdlib.h> | |
6d841bc2 | 33 | #include <stdint.h> |
9f1621ca MD |
34 | #include <string.h> |
35 | #include <errno.h> | |
36 | #include <poll.h> | |
37 | ||
4477a870 MD |
38 | #include <urcu/wfcqueue.h> |
39 | #include <urcu/map/urcu-qsbr.h> | |
727f819d | 40 | #define BUILD_QSBR_LIB |
4477a870 MD |
41 | #include <urcu/static/urcu-qsbr.h> |
42 | #include <urcu/pointer.h> | |
43 | #include <urcu/tls-compat.h> | |
71c811bf | 44 | |
4a6d7378 | 45 | #include "urcu-die.h" |
cba82d7b | 46 | #include "urcu-wait.h" |
ce28e67a | 47 | #include "urcu-utils.h" |
4a6d7378 | 48 | |
4477a870 | 49 | #define URCU_API_MAP |
9f1621ca | 50 | /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */ |
71c811bf | 51 | #undef _LGPL_SOURCE |
4477a870 | 52 | #include <urcu/urcu-qsbr.h> |
71c811bf | 53 | #define _LGPL_SOURCE |
9f1621ca | 54 | |
4477a870 | 55 | void __attribute__((destructor)) urcu_qsbr_exit(void); |
457eeeee | 56 | static void urcu_call_rcu_exit(void); |
f6d18c64 | 57 | |
731ccb96 MD |
58 | /* |
59 | * rcu_gp_lock ensures mutual exclusion between threads calling | |
60 | * synchronize_rcu(). | |
61 | */ | |
6abb4bd5 | 62 | static pthread_mutex_t rcu_gp_lock = PTHREAD_MUTEX_INITIALIZER; |
731ccb96 MD |
63 | /* |
64 | * rcu_registry_lock ensures mutual exclusion between threads | |
65 | * registering and unregistering themselves to/from the registry, and | |
66 | * with threads reading that registry from synchronize_rcu(). However, | |
67 | * this lock is not held all the way through the completion of awaiting | |
68 | * for the grace period. It is sporadically released between iterations | |
69 | * on the registry. | |
70 | * rcu_registry_lock may nest inside rcu_gp_lock. | |
71 | */ | |
72 | static pthread_mutex_t rcu_registry_lock = PTHREAD_MUTEX_INITIALIZER; | |
4477a870 | 73 | struct urcu_gp urcu_qsbr_gp = { .ctr = URCU_QSBR_GP_ONLINE }; |
ce28e67a | 74 | URCU_ATTR_ALIAS("urcu_qsbr_gp") extern struct urcu_gp rcu_gp_qsbr; |
9f1621ca | 75 | |
408f6d92 PB |
76 | /* |
77 | * Active attempts to check for reader Q.S. before calling futex(). | |
78 | */ | |
79 | #define RCU_QS_ACTIVE_ATTEMPTS 100 | |
80 | ||
9f1621ca MD |
81 | /* |
82 | * Written to only by each individual reader. Read by both the reader and the | |
83 | * writers. | |
84 | */ | |
4477a870 | 85 | DEFINE_URCU_TLS(struct urcu_qsbr_reader, urcu_qsbr_reader); |
99bfa9e9 | 86 | DEFINE_URCU_TLS_ALIAS(struct urcu_qsbr_reader, urcu_qsbr_reader, rcu_reader_qsbr); |
9f1621ca | 87 | |
16aa9ee8 | 88 | static CDS_LIST_HEAD(registry); |
9f1621ca | 89 | |
6362f68f | 90 | /* |
bf6822a6 | 91 | * Queue keeping threads awaiting to wait for a grace period. Contains |
6362f68f MD |
92 | * struct gp_waiters_thread objects. |
93 | */ | |
bf6822a6 | 94 | static DEFINE_URCU_WAIT_QUEUE(gp_waiters); |
6362f68f | 95 | |
6abb4bd5 | 96 | static void mutex_lock(pthread_mutex_t *mutex) |
9f1621ca MD |
97 | { |
98 | int ret; | |
99 | ||
100 | #ifndef DISTRUST_SIGNALS_EXTREME | |
6abb4bd5 | 101 | ret = pthread_mutex_lock(mutex); |
4a6d7378 MD |
102 | if (ret) |
103 | urcu_die(ret); | |
9f1621ca | 104 | #else /* #ifndef DISTRUST_SIGNALS_EXTREME */ |
6abb4bd5 | 105 | while ((ret = pthread_mutex_trylock(mutex)) != 0) { |
4a6d7378 MD |
106 | if (ret != EBUSY && ret != EINTR) |
107 | urcu_die(ret); | |
9f1621ca MD |
108 | poll(NULL,0,10); |
109 | } | |
110 | #endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */ | |
111 | } | |
112 | ||
6abb4bd5 | 113 | static void mutex_unlock(pthread_mutex_t *mutex) |
9f1621ca MD |
114 | { |
115 | int ret; | |
116 | ||
6abb4bd5 | 117 | ret = pthread_mutex_unlock(mutex); |
4a6d7378 MD |
118 | if (ret) |
119 | urcu_die(ret); | |
9f1621ca MD |
120 | } |
121 | ||
bc6c15bb MD |
122 | /* |
123 | * synchronize_rcu() waiting. Single thread. | |
124 | */ | |
4d703340 | 125 | static void wait_gp(void) |
bc6c15bb | 126 | { |
4d703340 | 127 | /* Read reader_gp before read futex */ |
5481ddb3 | 128 | cmm_smp_rmb(); |
b1bf6ed7 MD |
129 | while (uatomic_read(&urcu_qsbr_gp.futex) == -1) { |
130 | if (!futex_noasync(&urcu_qsbr_gp.futex, FUTEX_WAIT, -1, NULL, NULL, 0)) { | |
131 | /* | |
132 | * Prior queued wakeups queued by unrelated code | |
133 | * using the same address can cause futex wait to | |
134 | * return 0 even through the futex value is still | |
135 | * -1 (spurious wakeups). Check the value again | |
136 | * in user-space to validate whether it really | |
137 | * differs from -1. | |
138 | */ | |
139 | continue; | |
140 | } | |
b0a841b4 | 141 | switch (errno) { |
b1bf6ed7 | 142 | case EAGAIN: |
b0a841b4 MD |
143 | /* Value already changed. */ |
144 | return; | |
145 | case EINTR: | |
146 | /* Retry if interrupted by signal. */ | |
b1bf6ed7 | 147 | break; /* Get out of switch. Check again. */ |
b0a841b4 MD |
148 | default: |
149 | /* Unexpected error. */ | |
150 | urcu_die(errno); | |
151 | } | |
152 | } | |
bc6c15bb MD |
153 | } |
154 | ||
731ccb96 MD |
155 | /* |
156 | * Always called with rcu_registry lock held. Releases this lock between | |
157 | * iterations and grabs it again. Holds the lock when it returns. | |
158 | */ | |
708d89f0 MD |
159 | static void wait_for_readers(struct cds_list_head *input_readers, |
160 | struct cds_list_head *cur_snap_readers, | |
161 | struct cds_list_head *qsreaders) | |
9f1621ca | 162 | { |
9340c38d | 163 | unsigned int wait_loops = 0; |
4477a870 | 164 | struct urcu_qsbr_reader *index, *tmp; |
9f1621ca | 165 | |
9f1621ca | 166 | /* |
4477a870 | 167 | * Wait for each thread URCU_TLS(urcu_qsbr_reader).ctr to either |
f6b42f9c | 168 | * indicate quiescence (offline), or for them to observe the |
4477a870 | 169 | * current urcu_qsbr_gp.ctr value. |
9f1621ca | 170 | */ |
4d703340 | 171 | for (;;) { |
5e81fed7 MD |
172 | if (wait_loops < RCU_QS_ACTIVE_ATTEMPTS) |
173 | wait_loops++; | |
83a2c421 | 174 | if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { |
4477a870 | 175 | uatomic_set(&urcu_qsbr_gp.futex, -1); |
83a2c421 PB |
176 | /* |
177 | * Write futex before write waiting (the other side | |
178 | * reads them in the opposite order). | |
179 | */ | |
180 | cmm_smp_wmb(); | |
708d89f0 | 181 | cds_list_for_each_entry(index, input_readers, node) { |
83a2c421 PB |
182 | _CMM_STORE_SHARED(index->waiting, 1); |
183 | } | |
4d703340 | 184 | /* Write futex before read reader_gp */ |
5481ddb3 | 185 | cmm_smp_mb(); |
4d703340 | 186 | } |
708d89f0 | 187 | cds_list_for_each_entry_safe(index, tmp, input_readers, node) { |
4477a870 MD |
188 | switch (urcu_qsbr_reader_state(&index->ctr)) { |
189 | case URCU_READER_ACTIVE_CURRENT: | |
708d89f0 MD |
190 | if (cur_snap_readers) { |
191 | cds_list_move(&index->node, | |
192 | cur_snap_readers); | |
193 | break; | |
194 | } | |
195 | /* Fall-through */ | |
4477a870 | 196 | case URCU_READER_INACTIVE: |
708d89f0 MD |
197 | cds_list_move(&index->node, qsreaders); |
198 | break; | |
4477a870 | 199 | case URCU_READER_ACTIVE_OLD: |
708d89f0 MD |
200 | /* |
201 | * Old snapshot. Leaving node in | |
202 | * input_readers will make us busy-loop | |
203 | * until the snapshot becomes current or | |
204 | * the reader becomes inactive. | |
205 | */ | |
206 | break; | |
207 | } | |
4d703340 | 208 | } |
bc6c15bb | 209 | |
708d89f0 | 210 | if (cds_list_empty(input_readers)) { |
83a2c421 | 211 | if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { |
4d703340 | 212 | /* Read reader_gp before write futex */ |
5481ddb3 | 213 | cmm_smp_mb(); |
4477a870 | 214 | uatomic_set(&urcu_qsbr_gp.futex, 0); |
4d703340 MD |
215 | } |
216 | break; | |
217 | } else { | |
731ccb96 MD |
218 | /* Temporarily unlock the registry lock. */ |
219 | mutex_unlock(&rcu_registry_lock); | |
83a2c421 | 220 | if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS) { |
4d703340 | 221 | wait_gp(); |
bc6c15bb | 222 | } else { |
9f1621ca | 223 | #ifndef HAS_INCOHERENT_CACHES |
06f22bdb | 224 | caa_cpu_relax(); |
9f1621ca | 225 | #else /* #ifndef HAS_INCOHERENT_CACHES */ |
5481ddb3 | 226 | cmm_smp_mb(); |
9f1621ca | 227 | #endif /* #else #ifndef HAS_INCOHERENT_CACHES */ |
bc6c15bb | 228 | } |
731ccb96 MD |
229 | /* Re-lock the registry lock before the next loop. */ |
230 | mutex_lock(&rcu_registry_lock); | |
bc6c15bb | 231 | } |
9f1621ca MD |
232 | } |
233 | } | |
234 | ||
47d2f29e MD |
235 | /* |
236 | * Using a two-subphases algorithm for architectures with smaller than 64-bit | |
237 | * long-size to ensure we do not encounter an overflow bug. | |
238 | */ | |
239 | ||
b39e1761 | 240 | #if (CAA_BITS_PER_LONG < 64) |
4477a870 | 241 | void urcu_qsbr_synchronize_rcu(void) |
47d2f29e | 242 | { |
708d89f0 MD |
243 | CDS_LIST_HEAD(cur_snap_readers); |
244 | CDS_LIST_HEAD(qsreaders); | |
bc49c323 | 245 | unsigned long was_online; |
bf6822a6 MD |
246 | DEFINE_URCU_WAIT_NODE(wait, URCU_WAIT_WAITING); |
247 | struct urcu_waiters waiters; | |
bc49c323 | 248 | |
4477a870 | 249 | was_online = urcu_qsbr_read_ongoing(); |
bc49c323 | 250 | |
47d2f29e | 251 | /* All threads should read qparity before accessing data structure |
27b940e7 PB |
252 | * where new ptr points to. In the "then" case, rcu_thread_offline |
253 | * includes a memory barrier. | |
254 | * | |
bc49c323 | 255 | * Mark the writer thread offline to make sure we don't wait for |
5e77fc1f PM |
256 | * our own quiescent state. This allows using synchronize_rcu() |
257 | * in threads registered as readers. | |
bc49c323 | 258 | */ |
27b940e7 | 259 | if (was_online) |
4477a870 | 260 | urcu_qsbr_thread_offline(); |
27b940e7 PB |
261 | else |
262 | cmm_smp_mb(); | |
bc49c323 | 263 | |
6362f68f | 264 | /* |
bf6822a6 | 265 | * Add ourself to gp_waiters queue of threads awaiting to wait |
6362f68f | 266 | * for a grace period. Proceed to perform the grace period only |
bf6822a6 | 267 | * if we are the first thread added into the queue. |
6362f68f | 268 | */ |
bf6822a6 MD |
269 | if (urcu_wait_add(&gp_waiters, &wait) != 0) { |
270 | /* Not first in queue: will be awakened by another thread. */ | |
271 | urcu_adaptative_busy_wait(&wait); | |
6362f68f MD |
272 | goto gp_end; |
273 | } | |
bf6822a6 MD |
274 | /* We won't need to wake ourself up */ |
275 | urcu_wait_set_state(&wait, URCU_WAIT_RUNNING); | |
6362f68f | 276 | |
6abb4bd5 | 277 | mutex_lock(&rcu_gp_lock); |
47d2f29e | 278 | |
6362f68f | 279 | /* |
bf6822a6 | 280 | * Move all waiters into our local queue. |
6362f68f | 281 | */ |
bf6822a6 | 282 | urcu_move_waiters(&waiters, &gp_waiters); |
6362f68f | 283 | |
731ccb96 MD |
284 | mutex_lock(&rcu_registry_lock); |
285 | ||
16aa9ee8 | 286 | if (cds_list_empty(®istry)) |
2dfb8b5e | 287 | goto out; |
47d2f29e MD |
288 | |
289 | /* | |
f6b42f9c | 290 | * Wait for readers to observe original parity or be quiescent. |
731ccb96 MD |
291 | * wait_for_readers() can release and grab again rcu_registry_lock |
292 | * interally. | |
47d2f29e | 293 | */ |
708d89f0 | 294 | wait_for_readers(®istry, &cur_snap_readers, &qsreaders); |
47d2f29e MD |
295 | |
296 | /* | |
f6b42f9c | 297 | * Must finish waiting for quiescent state for original parity |
4477a870 | 298 | * before committing next urcu_qsbr_gp.ctr update to memory. Failure |
f6b42f9c | 299 | * to do so could result in the writer waiting forever while new |
5e77fc1f | 300 | * readers are always accessing data (no progress). Enforce |
4477a870 MD |
301 | * compiler-order of load URCU_TLS(urcu_qsbr_reader).ctr before store |
302 | * to urcu_qsbr_gp.ctr. | |
47d2f29e | 303 | */ |
5481ddb3 | 304 | cmm_barrier(); |
47d2f29e | 305 | |
47d2f29e | 306 | /* |
5481ddb3 | 307 | * Adding a cmm_smp_mb() which is _not_ formally required, but makes the |
2dfb8b5e MD |
308 | * model easier to understand. It does not have a big performance impact |
309 | * anyway, given this is the write-side. | |
47d2f29e | 310 | */ |
5481ddb3 | 311 | cmm_smp_mb(); |
47d2f29e | 312 | |
f6b42f9c | 313 | /* Switch parity: 0 -> 1, 1 -> 0 */ |
4477a870 | 314 | CMM_STORE_SHARED(urcu_qsbr_gp.ctr, urcu_qsbr_gp.ctr ^ URCU_QSBR_GP_CTR); |
f6b42f9c | 315 | |
47d2f29e | 316 | /* |
4477a870 | 317 | * Must commit urcu_qsbr_gp.ctr update to memory before waiting for |
f6b42f9c MD |
318 | * quiescent state. Failure to do so could result in the writer |
319 | * waiting forever while new readers are always accessing data | |
4477a870 MD |
320 | * (no progress). Enforce compiler-order of store to urcu_qsbr_gp.ctr |
321 | * before load URCU_TLS(urcu_qsbr_reader).ctr. | |
47d2f29e | 322 | */ |
f6b42f9c MD |
323 | cmm_barrier(); |
324 | ||
325 | /* | |
326 | * Adding a cmm_smp_mb() which is _not_ formally required, but makes the | |
327 | * model easier to understand. It does not have a big performance impact | |
328 | * anyway, given this is the write-side. | |
329 | */ | |
330 | cmm_smp_mb(); | |
331 | ||
332 | /* | |
333 | * Wait for readers to observe new parity or be quiescent. | |
731ccb96 MD |
334 | * wait_for_readers() can release and grab again rcu_registry_lock |
335 | * interally. | |
f6b42f9c | 336 | */ |
708d89f0 MD |
337 | wait_for_readers(&cur_snap_readers, NULL, &qsreaders); |
338 | ||
339 | /* | |
340 | * Put quiescent reader list back into registry. | |
341 | */ | |
342 | cds_list_splice(&qsreaders, ®istry); | |
2dfb8b5e | 343 | out: |
731ccb96 | 344 | mutex_unlock(&rcu_registry_lock); |
6abb4bd5 | 345 | mutex_unlock(&rcu_gp_lock); |
bf6822a6 | 346 | urcu_wake_all_waiters(&waiters); |
6362f68f | 347 | gp_end: |
bc49c323 MD |
348 | /* |
349 | * Finish waiting for reader threads before letting the old ptr being | |
47d2f29e MD |
350 | * freed. |
351 | */ | |
bc49c323 | 352 | if (was_online) |
4477a870 | 353 | urcu_qsbr_thread_online(); |
27b940e7 PB |
354 | else |
355 | cmm_smp_mb(); | |
47d2f29e | 356 | } |
b39e1761 | 357 | #else /* !(CAA_BITS_PER_LONG < 64) */ |
4477a870 | 358 | void urcu_qsbr_synchronize_rcu(void) |
9f1621ca | 359 | { |
708d89f0 | 360 | CDS_LIST_HEAD(qsreaders); |
f0f7dbdd | 361 | unsigned long was_online; |
bf6822a6 MD |
362 | DEFINE_URCU_WAIT_NODE(wait, URCU_WAIT_WAITING); |
363 | struct urcu_waiters waiters; | |
ff2f67a0 | 364 | |
4477a870 | 365 | was_online = urcu_qsbr_read_ongoing(); |
ff2f67a0 MD |
366 | |
367 | /* | |
368 | * Mark the writer thread offline to make sure we don't wait for | |
5e77fc1f PM |
369 | * our own quiescent state. This allows using synchronize_rcu() |
370 | * in threads registered as readers. | |
ff2f67a0 | 371 | */ |
27b940e7 | 372 | if (was_online) |
4477a870 | 373 | urcu_qsbr_thread_offline(); |
27b940e7 PB |
374 | else |
375 | cmm_smp_mb(); | |
ff2f67a0 | 376 | |
6362f68f | 377 | /* |
bf6822a6 | 378 | * Add ourself to gp_waiters queue of threads awaiting to wait |
6362f68f | 379 | * for a grace period. Proceed to perform the grace period only |
bf6822a6 | 380 | * if we are the first thread added into the queue. |
6362f68f | 381 | */ |
bf6822a6 MD |
382 | if (urcu_wait_add(&gp_waiters, &wait) != 0) { |
383 | /* Not first in queue: will be awakened by another thread. */ | |
384 | urcu_adaptative_busy_wait(&wait); | |
6362f68f MD |
385 | goto gp_end; |
386 | } | |
bf6822a6 MD |
387 | /* We won't need to wake ourself up */ |
388 | urcu_wait_set_state(&wait, URCU_WAIT_RUNNING); | |
6362f68f | 389 | |
6abb4bd5 | 390 | mutex_lock(&rcu_gp_lock); |
6362f68f MD |
391 | |
392 | /* | |
bf6822a6 | 393 | * Move all waiters into our local queue. |
6362f68f | 394 | */ |
bf6822a6 | 395 | urcu_move_waiters(&waiters, &gp_waiters); |
6362f68f | 396 | |
731ccb96 MD |
397 | mutex_lock(&rcu_registry_lock); |
398 | ||
16aa9ee8 | 399 | if (cds_list_empty(®istry)) |
2dfb8b5e | 400 | goto out; |
f6b42f9c MD |
401 | |
402 | /* Increment current G.P. */ | |
4477a870 | 403 | CMM_STORE_SHARED(urcu_qsbr_gp.ctr, urcu_qsbr_gp.ctr + URCU_QSBR_GP_CTR); |
f6b42f9c MD |
404 | |
405 | /* | |
4477a870 | 406 | * Must commit urcu_qsbr_gp.ctr update to memory before waiting for |
f6b42f9c MD |
407 | * quiescent state. Failure to do so could result in the writer |
408 | * waiting forever while new readers are always accessing data | |
4477a870 MD |
409 | * (no progress). Enforce compiler-order of store to urcu_qsbr_gp.ctr |
410 | * before load URCU_TLS(urcu_qsbr_reader).ctr. | |
f6b42f9c MD |
411 | */ |
412 | cmm_barrier(); | |
413 | ||
414 | /* | |
415 | * Adding a cmm_smp_mb() which is _not_ formally required, but makes the | |
416 | * model easier to understand. It does not have a big performance impact | |
417 | * anyway, given this is the write-side. | |
418 | */ | |
419 | cmm_smp_mb(); | |
420 | ||
421 | /* | |
422 | * Wait for readers to observe new count of be quiescent. | |
731ccb96 MD |
423 | * wait_for_readers() can release and grab again rcu_registry_lock |
424 | * interally. | |
f6b42f9c | 425 | */ |
708d89f0 MD |
426 | wait_for_readers(®istry, NULL, &qsreaders); |
427 | ||
428 | /* | |
429 | * Put quiescent reader list back into registry. | |
430 | */ | |
431 | cds_list_splice(&qsreaders, ®istry); | |
2dfb8b5e | 432 | out: |
731ccb96 | 433 | mutex_unlock(&rcu_registry_lock); |
6abb4bd5 | 434 | mutex_unlock(&rcu_gp_lock); |
bf6822a6 | 435 | urcu_wake_all_waiters(&waiters); |
6362f68f | 436 | gp_end: |
ff2f67a0 | 437 | if (was_online) |
4477a870 | 438 | urcu_qsbr_thread_online(); |
27b940e7 PB |
439 | else |
440 | cmm_smp_mb(); | |
9f1621ca | 441 | } |
b39e1761 | 442 | #endif /* !(CAA_BITS_PER_LONG < 64) */ |
ce28e67a | 443 | URCU_ATTR_ALIAS("urcu_qsbr_synchronize_rcu") |
4477a870 | 444 | void synchronize_rcu_qsbr(); |
9f1621ca MD |
445 | |
446 | /* | |
447 | * library wrappers to be used by non-LGPL compatible source code. | |
448 | */ | |
449 | ||
4477a870 | 450 | void urcu_qsbr_read_lock(void) |
9f1621ca | 451 | { |
4477a870 | 452 | _urcu_qsbr_read_lock(); |
9f1621ca | 453 | } |
ce28e67a | 454 | URCU_ATTR_ALIAS("urcu_qsbr_read_lock") void rcu_read_lock_qsbr(); |
9f1621ca | 455 | |
4477a870 | 456 | void urcu_qsbr_read_unlock(void) |
9f1621ca | 457 | { |
4477a870 | 458 | _urcu_qsbr_read_unlock(); |
9f1621ca | 459 | } |
ce28e67a | 460 | URCU_ATTR_ALIAS("urcu_qsbr_read_unlock") void rcu_read_unlock_qsbr(); |
9f1621ca | 461 | |
4477a870 | 462 | int urcu_qsbr_read_ongoing(void) |
882f3357 | 463 | { |
4477a870 | 464 | return _urcu_qsbr_read_ongoing(); |
882f3357 | 465 | } |
ce28e67a | 466 | URCU_ATTR_ALIAS("urcu_qsbr_read_ongoing") |
4477a870 | 467 | void rcu_read_ongoing_qsbr(); |
882f3357 | 468 | |
4477a870 | 469 | void urcu_qsbr_quiescent_state(void) |
7ac06cef | 470 | { |
4477a870 | 471 | _urcu_qsbr_quiescent_state(); |
7ac06cef | 472 | } |
ce28e67a | 473 | URCU_ATTR_ALIAS("urcu_qsbr_quiescent_state") |
4477a870 | 474 | void rcu_quiescent_state_qsbr(); |
7ac06cef | 475 | |
4477a870 | 476 | void urcu_qsbr_thread_offline(void) |
7ac06cef | 477 | { |
4477a870 | 478 | _urcu_qsbr_thread_offline(); |
7ac06cef | 479 | } |
ce28e67a | 480 | URCU_ATTR_ALIAS("urcu_qsbr_thread_offline") |
4477a870 | 481 | void rcu_thread_offline_qsbr(); |
7ac06cef | 482 | |
4477a870 | 483 | void urcu_qsbr_thread_online(void) |
7ac06cef | 484 | { |
4477a870 | 485 | _urcu_qsbr_thread_online(); |
7ac06cef | 486 | } |
ce28e67a | 487 | URCU_ATTR_ALIAS("urcu_qsbr_thread_online") |
4477a870 | 488 | void rcu_thread_online_qsbr(); |
7ac06cef | 489 | |
4477a870 | 490 | void urcu_qsbr_register_thread(void) |
9f1621ca | 491 | { |
4477a870 MD |
492 | URCU_TLS(urcu_qsbr_reader).tid = pthread_self(); |
493 | assert(URCU_TLS(urcu_qsbr_reader).ctr == 0); | |
4f8e3380 | 494 | |
731ccb96 | 495 | mutex_lock(&rcu_registry_lock); |
4477a870 MD |
496 | assert(!URCU_TLS(urcu_qsbr_reader).registered); |
497 | URCU_TLS(urcu_qsbr_reader).registered = 1; | |
498 | cds_list_add(&URCU_TLS(urcu_qsbr_reader).node, ®istry); | |
731ccb96 | 499 | mutex_unlock(&rcu_registry_lock); |
4477a870 | 500 | _urcu_qsbr_thread_online(); |
9f1621ca | 501 | } |
ce28e67a | 502 | URCU_ATTR_ALIAS("urcu_qsbr_register_thread") |
4477a870 | 503 | void rcu_register_thread_qsbr(); |
9f1621ca | 504 | |
4477a870 | 505 | void urcu_qsbr_unregister_thread(void) |
9f1621ca | 506 | { |
76f3022f MD |
507 | /* |
508 | * We have to make the thread offline otherwise we end up dealocking | |
509 | * with a waiting writer. | |
510 | */ | |
4477a870 MD |
511 | _urcu_qsbr_thread_offline(); |
512 | assert(URCU_TLS(urcu_qsbr_reader).registered); | |
513 | URCU_TLS(urcu_qsbr_reader).registered = 0; | |
731ccb96 | 514 | mutex_lock(&rcu_registry_lock); |
4477a870 | 515 | cds_list_del(&URCU_TLS(urcu_qsbr_reader).node); |
731ccb96 | 516 | mutex_unlock(&rcu_registry_lock); |
9f1621ca | 517 | } |
ce28e67a | 518 | URCU_ATTR_ALIAS("urcu_qsbr_unregister_thread") |
4477a870 | 519 | void rcu_unregister_thread_qsbr(); |
f6d18c64 | 520 | |
4477a870 | 521 | void urcu_qsbr_exit(void) |
f6d18c64 | 522 | { |
01cadde4 MD |
523 | /* |
524 | * Assertion disabled because call_rcu threads are now rcu | |
525 | * readers, and left running at exit. | |
526 | * assert(cds_list_empty(®istry)); | |
527 | */ | |
457eeeee | 528 | urcu_call_rcu_exit(); |
f6d18c64 | 529 | } |
ce28e67a | 530 | URCU_ATTR_ALIAS("urcu_qsbr_exit") void rcu_exit_qsbr(); |
5e77fc1f | 531 | |
5e6b23a6 | 532 | DEFINE_RCU_FLAVOR(rcu_flavor); |
4477a870 | 533 | DEFINE_RCU_FLAVOR_ALIAS(rcu_flavor, alias_rcu_flavor); |
541d828d | 534 | |
5e77fc1f | 535 | #include "urcu-call-rcu-impl.h" |
0376e7b2 | 536 | #include "urcu-defer-impl.h" |