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