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