Fix: call_rcu: teardown default call_rcu worker on application exit
[urcu.git] / src / urcu-bp.c
1 /*
2 * urcu-bp.c
3 *
4 * Userspace RCU library, "bulletproof" version.
5 *
6 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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
26 #define URCU_NO_COMPAT_IDENTIFIERS
27 #define _LGPL_SOURCE
28 #include <stdio.h>
29 #include <pthread.h>
30 #include <signal.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <poll.h>
35 #include <unistd.h>
36 #include <stdbool.h>
37 #include <sys/mman.h>
38
39 #include <urcu/assert.h>
40 #include <urcu/config.h>
41 #include <urcu/arch.h>
42 #include <urcu/wfcqueue.h>
43 #include <urcu/map/urcu-bp.h>
44 #include <urcu/static/urcu-bp.h>
45 #include <urcu/pointer.h>
46 #include <urcu/tls-compat.h>
47
48 #include "urcu-die.h"
49 #include "urcu-utils.h"
50
51 #define URCU_API_MAP
52 /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
53 #undef _LGPL_SOURCE
54 #include <urcu/urcu-bp.h>
55 #define _LGPL_SOURCE
56
57 #ifndef MAP_ANONYMOUS
58 #define MAP_ANONYMOUS MAP_ANON
59 #endif
60
61 #ifdef __linux__
62 static
63 void *mremap_wrapper(void *old_address, size_t old_size,
64 size_t new_size, int flags)
65 {
66 return mremap(old_address, old_size, new_size, flags);
67 }
68 #else
69
70 #define MREMAP_MAYMOVE 1
71 #define MREMAP_FIXED 2
72
73 /*
74 * mremap wrapper for non-Linux systems not allowing MAYMOVE.
75 * This is not generic.
76 */
77 static
78 void *mremap_wrapper(void *old_address __attribute__((unused)),
79 size_t old_size __attribute__((unused)),
80 size_t new_size __attribute__((unused)),
81 int flags)
82 {
83 urcu_posix_assert(!(flags & MREMAP_MAYMOVE));
84
85 return MAP_FAILED;
86 }
87 #endif
88
89 /* Sleep delay in ms */
90 #define RCU_SLEEP_DELAY_MS 10
91 #define INIT_NR_THREADS 8
92 #define ARENA_INIT_ALLOC \
93 sizeof(struct registry_chunk) \
94 + INIT_NR_THREADS * sizeof(struct urcu_bp_reader)
95
96 /*
97 * Active attempts to check for reader Q.S. before calling sleep().
98 */
99 #define RCU_QS_ACTIVE_ATTEMPTS 100
100
101 static
102 int urcu_bp_refcount;
103
104 /* If the headers do not support membarrier system call, fall back smp_mb. */
105 #ifdef __NR_membarrier
106 # define membarrier(...) syscall(__NR_membarrier, __VA_ARGS__)
107 #else
108 # define membarrier(...) -ENOSYS
109 #endif
110
111 enum membarrier_cmd {
112 MEMBARRIER_CMD_QUERY = 0,
113 MEMBARRIER_CMD_SHARED = (1 << 0),
114 /* reserved for MEMBARRIER_CMD_SHARED_EXPEDITED (1 << 1) */
115 /* reserved for MEMBARRIER_CMD_PRIVATE (1 << 2) */
116 MEMBARRIER_CMD_PRIVATE_EXPEDITED = (1 << 3),
117 MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED = (1 << 4),
118 };
119
120 static
121 void __attribute__((constructor)) _urcu_bp_init(void);
122 static
123 void __attribute__((destructor)) urcu_bp_exit(void);
124 static void urcu_call_rcu_exit(void);
125
126 #ifndef CONFIG_RCU_FORCE_SYS_MEMBARRIER
127 int urcu_bp_has_sys_membarrier;
128 #endif
129
130 /*
131 * rcu_gp_lock ensures mutual exclusion between threads calling
132 * synchronize_rcu().
133 */
134 static pthread_mutex_t rcu_gp_lock = PTHREAD_MUTEX_INITIALIZER;
135 /*
136 * rcu_registry_lock ensures mutual exclusion between threads
137 * registering and unregistering themselves to/from the registry, and
138 * with threads reading that registry from synchronize_rcu(). However,
139 * this lock is not held all the way through the completion of awaiting
140 * for the grace period. It is sporadically released between iterations
141 * on the registry.
142 * rcu_registry_lock may nest inside rcu_gp_lock.
143 */
144 static pthread_mutex_t rcu_registry_lock = PTHREAD_MUTEX_INITIALIZER;
145
146 static pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
147 static int initialized;
148
149 static pthread_key_t urcu_bp_key;
150
151 struct urcu_bp_gp urcu_bp_gp = { .ctr = URCU_BP_GP_COUNT };
152
153 /*
154 * Pointer to registry elements. Written to only by each individual reader. Read
155 * by both the reader and the writers.
156 */
157 DEFINE_URCU_TLS(struct urcu_bp_reader *, urcu_bp_reader);
158
159 static CDS_LIST_HEAD(registry);
160
161 struct registry_chunk {
162 size_t data_len; /* data length */
163 size_t used; /* amount of data used */
164 struct cds_list_head node; /* chunk_list node */
165 char data[];
166 };
167
168 struct registry_arena {
169 struct cds_list_head chunk_list;
170 };
171
172 static struct registry_arena registry_arena = {
173 .chunk_list = CDS_LIST_HEAD_INIT(registry_arena.chunk_list),
174 };
175
176 /* Saved fork signal mask, protected by rcu_gp_lock */
177 static sigset_t saved_fork_signal_mask;
178
179 static void mutex_lock(pthread_mutex_t *mutex)
180 {
181 int ret;
182
183 #ifndef DISTRUST_SIGNALS_EXTREME
184 ret = pthread_mutex_lock(mutex);
185 if (ret)
186 urcu_die(ret);
187 #else /* #ifndef DISTRUST_SIGNALS_EXTREME */
188 while ((ret = pthread_mutex_trylock(mutex)) != 0) {
189 if (ret != EBUSY && ret != EINTR)
190 urcu_die(ret);
191 poll(NULL,0,10);
192 }
193 #endif /* #else #ifndef DISTRUST_SIGNALS_EXTREME */
194 }
195
196 static void mutex_unlock(pthread_mutex_t *mutex)
197 {
198 int ret;
199
200 ret = pthread_mutex_unlock(mutex);
201 if (ret)
202 urcu_die(ret);
203 }
204
205 static void smp_mb_master(void)
206 {
207 if (caa_likely(urcu_bp_has_sys_membarrier)) {
208 if (membarrier(MEMBARRIER_CMD_PRIVATE_EXPEDITED, 0))
209 urcu_die(errno);
210 } else {
211 cmm_smp_mb();
212 }
213 }
214
215 /*
216 * Always called with rcu_registry lock held. Releases this lock between
217 * iterations and grabs it again. Holds the lock when it returns.
218 */
219 static void wait_for_readers(struct cds_list_head *input_readers,
220 struct cds_list_head *cur_snap_readers,
221 struct cds_list_head *qsreaders)
222 {
223 unsigned int wait_loops = 0;
224 struct urcu_bp_reader *index, *tmp;
225
226 /*
227 * Wait for each thread URCU_TLS(urcu_bp_reader).ctr to either
228 * indicate quiescence (not nested), or observe the current
229 * rcu_gp.ctr value.
230 */
231 for (;;) {
232 if (wait_loops < RCU_QS_ACTIVE_ATTEMPTS)
233 wait_loops++;
234
235 cds_list_for_each_entry_safe(index, tmp, input_readers, node) {
236 switch (urcu_bp_reader_state(&index->ctr)) {
237 case URCU_BP_READER_ACTIVE_CURRENT:
238 if (cur_snap_readers) {
239 cds_list_move(&index->node,
240 cur_snap_readers);
241 break;
242 }
243 /* Fall-through */
244 case URCU_BP_READER_INACTIVE:
245 cds_list_move(&index->node, qsreaders);
246 break;
247 case URCU_BP_READER_ACTIVE_OLD:
248 /*
249 * Old snapshot. Leaving node in
250 * input_readers will make us busy-loop
251 * until the snapshot becomes current or
252 * the reader becomes inactive.
253 */
254 break;
255 }
256 }
257
258 if (cds_list_empty(input_readers)) {
259 break;
260 } else {
261 /* Temporarily unlock the registry lock. */
262 mutex_unlock(&rcu_registry_lock);
263 if (wait_loops >= RCU_QS_ACTIVE_ATTEMPTS)
264 (void) poll(NULL, 0, RCU_SLEEP_DELAY_MS);
265 else
266 caa_cpu_relax();
267 /* Re-lock the registry lock before the next loop. */
268 mutex_lock(&rcu_registry_lock);
269 }
270 }
271 }
272
273 void urcu_bp_synchronize_rcu(void)
274 {
275 CDS_LIST_HEAD(cur_snap_readers);
276 CDS_LIST_HEAD(qsreaders);
277 sigset_t newmask, oldmask;
278 int ret;
279
280 ret = sigfillset(&newmask);
281 urcu_posix_assert(!ret);
282 ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
283 urcu_posix_assert(!ret);
284
285 mutex_lock(&rcu_gp_lock);
286
287 mutex_lock(&rcu_registry_lock);
288
289 if (cds_list_empty(&registry))
290 goto out;
291
292 /* All threads should read qparity before accessing data structure
293 * where new ptr points to. */
294 /* Write new ptr before changing the qparity */
295 smp_mb_master();
296
297 /*
298 * Wait for readers to observe original parity or be quiescent.
299 * wait_for_readers() can release and grab again rcu_registry_lock
300 * internally.
301 */
302 wait_for_readers(&registry, &cur_snap_readers, &qsreaders);
303
304 /*
305 * Adding a cmm_smp_mb() which is _not_ formally required, but makes the
306 * model easier to understand. It does not have a big performance impact
307 * anyway, given this is the write-side.
308 */
309 cmm_smp_mb();
310
311 /* Switch parity: 0 -> 1, 1 -> 0 */
312 CMM_STORE_SHARED(rcu_gp.ctr, rcu_gp.ctr ^ URCU_BP_GP_CTR_PHASE);
313
314 /*
315 * Must commit qparity update to memory before waiting for other parity
316 * quiescent state. Failure to do so could result in the writer waiting
317 * forever while new readers are always accessing data (no progress).
318 * Ensured by CMM_STORE_SHARED and CMM_LOAD_SHARED.
319 */
320
321 /*
322 * Adding a cmm_smp_mb() which is _not_ formally required, but makes the
323 * model easier to understand. It does not have a big performance impact
324 * anyway, given this is the write-side.
325 */
326 cmm_smp_mb();
327
328 /*
329 * Wait for readers to observe new parity or be quiescent.
330 * wait_for_readers() can release and grab again rcu_registry_lock
331 * internally.
332 */
333 wait_for_readers(&cur_snap_readers, NULL, &qsreaders);
334
335 /*
336 * Put quiescent reader list back into registry.
337 */
338 cds_list_splice(&qsreaders, &registry);
339
340 /*
341 * Finish waiting for reader threads before letting the old ptr being
342 * freed.
343 */
344 smp_mb_master();
345 out:
346 mutex_unlock(&rcu_registry_lock);
347 mutex_unlock(&rcu_gp_lock);
348 ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
349 urcu_posix_assert(!ret);
350 }
351
352 /*
353 * library wrappers to be used by non-LGPL compatible source code.
354 */
355
356 void urcu_bp_read_lock(void)
357 {
358 _urcu_bp_read_lock();
359 }
360
361 void urcu_bp_read_unlock(void)
362 {
363 _urcu_bp_read_unlock();
364 }
365
366 int urcu_bp_read_ongoing(void)
367 {
368 return _urcu_bp_read_ongoing();
369 }
370
371 /*
372 * Only grow for now. If empty, allocate a ARENA_INIT_ALLOC sized chunk.
373 * Else, try expanding the last chunk. If this fails, allocate a new
374 * chunk twice as big as the last chunk.
375 * Memory used by chunks _never_ moves. A chunk could theoretically be
376 * freed when all "used" slots are released, but we don't do it at this
377 * point.
378 */
379 static
380 void expand_arena(struct registry_arena *arena)
381 {
382 struct registry_chunk *new_chunk, *last_chunk;
383 size_t old_chunk_len, new_chunk_len;
384
385 /* No chunk. */
386 if (cds_list_empty(&arena->chunk_list)) {
387 urcu_posix_assert(ARENA_INIT_ALLOC >=
388 sizeof(struct registry_chunk)
389 + sizeof(struct rcu_reader));
390 new_chunk_len = ARENA_INIT_ALLOC;
391 new_chunk = (struct registry_chunk *) mmap(NULL,
392 new_chunk_len,
393 PROT_READ | PROT_WRITE,
394 MAP_ANONYMOUS | MAP_PRIVATE,
395 -1, 0);
396 if (new_chunk == MAP_FAILED)
397 abort();
398 memset(new_chunk, 0, new_chunk_len);
399 new_chunk->data_len =
400 new_chunk_len - sizeof(struct registry_chunk);
401 cds_list_add_tail(&new_chunk->node, &arena->chunk_list);
402 return; /* We're done. */
403 }
404
405 /* Try expanding last chunk. */
406 last_chunk = cds_list_entry(arena->chunk_list.prev,
407 struct registry_chunk, node);
408 old_chunk_len =
409 last_chunk->data_len + sizeof(struct registry_chunk);
410 new_chunk_len = old_chunk_len << 1;
411
412 /* Don't allow memory mapping to move, just expand. */
413 new_chunk = mremap_wrapper(last_chunk, old_chunk_len,
414 new_chunk_len, 0);
415 if (new_chunk != MAP_FAILED) {
416 /* Should not have moved. */
417 urcu_posix_assert(new_chunk == last_chunk);
418 memset((char *) last_chunk + old_chunk_len, 0,
419 new_chunk_len - old_chunk_len);
420 last_chunk->data_len =
421 new_chunk_len - sizeof(struct registry_chunk);
422 return; /* We're done. */
423 }
424
425 /* Remap did not succeed, we need to add a new chunk. */
426 new_chunk = (struct registry_chunk *) mmap(NULL,
427 new_chunk_len,
428 PROT_READ | PROT_WRITE,
429 MAP_ANONYMOUS | MAP_PRIVATE,
430 -1, 0);
431 if (new_chunk == MAP_FAILED)
432 abort();
433 memset(new_chunk, 0, new_chunk_len);
434 new_chunk->data_len =
435 new_chunk_len - sizeof(struct registry_chunk);
436 cds_list_add_tail(&new_chunk->node, &arena->chunk_list);
437 }
438
439 static
440 struct rcu_reader *arena_alloc(struct registry_arena *arena)
441 {
442 struct registry_chunk *chunk;
443 struct rcu_reader *rcu_reader_reg;
444 int expand_done = 0; /* Only allow to expand once per alloc */
445 size_t len = sizeof(struct rcu_reader);
446
447 retry:
448 cds_list_for_each_entry(chunk, &arena->chunk_list, node) {
449 if (chunk->data_len - chunk->used < len)
450 continue;
451 /* Find spot */
452 for (rcu_reader_reg = (struct rcu_reader *) &chunk->data[0];
453 rcu_reader_reg < (struct rcu_reader *) &chunk->data[chunk->data_len];
454 rcu_reader_reg++) {
455 if (!rcu_reader_reg->alloc) {
456 rcu_reader_reg->alloc = 1;
457 chunk->used += len;
458 return rcu_reader_reg;
459 }
460 }
461 }
462
463 if (!expand_done) {
464 expand_arena(arena);
465 expand_done = 1;
466 goto retry;
467 }
468
469 return NULL;
470 }
471
472 /* Called with signals off and mutex locked */
473 static
474 void add_thread(void)
475 {
476 struct rcu_reader *rcu_reader_reg;
477 int ret;
478
479 rcu_reader_reg = arena_alloc(&registry_arena);
480 if (!rcu_reader_reg)
481 abort();
482 ret = pthread_setspecific(urcu_bp_key, rcu_reader_reg);
483 if (ret)
484 abort();
485
486 /* Add to registry */
487 rcu_reader_reg->tid = pthread_self();
488 urcu_posix_assert(rcu_reader_reg->ctr == 0);
489 cds_list_add(&rcu_reader_reg->node, &registry);
490 /*
491 * Reader threads are pointing to the reader registry. This is
492 * why its memory should never be relocated.
493 */
494 URCU_TLS(urcu_bp_reader) = rcu_reader_reg;
495 }
496
497 /* Called with mutex locked */
498 static
499 void cleanup_thread(struct registry_chunk *chunk,
500 struct rcu_reader *rcu_reader_reg)
501 {
502 rcu_reader_reg->ctr = 0;
503 cds_list_del(&rcu_reader_reg->node);
504 rcu_reader_reg->tid = 0;
505 rcu_reader_reg->alloc = 0;
506 chunk->used -= sizeof(struct rcu_reader);
507 }
508
509 static
510 struct registry_chunk *find_chunk(struct rcu_reader *rcu_reader_reg)
511 {
512 struct registry_chunk *chunk;
513
514 cds_list_for_each_entry(chunk, &registry_arena.chunk_list, node) {
515 if (rcu_reader_reg < (struct rcu_reader *) &chunk->data[0])
516 continue;
517 if (rcu_reader_reg >= (struct rcu_reader *) &chunk->data[chunk->data_len])
518 continue;
519 return chunk;
520 }
521 return NULL;
522 }
523
524 /* Called with signals off and mutex locked */
525 static
526 void remove_thread(struct rcu_reader *rcu_reader_reg)
527 {
528 cleanup_thread(find_chunk(rcu_reader_reg), rcu_reader_reg);
529 URCU_TLS(urcu_bp_reader) = NULL;
530 }
531
532 /* Disable signals, take mutex, add to registry */
533 void urcu_bp_register(void)
534 {
535 sigset_t newmask, oldmask;
536 int ret;
537
538 ret = sigfillset(&newmask);
539 if (ret)
540 abort();
541 ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
542 if (ret)
543 abort();
544
545 /*
546 * Check if a signal concurrently registered our thread since
547 * the check in rcu_read_lock().
548 */
549 if (URCU_TLS(urcu_bp_reader))
550 goto end;
551
552 /*
553 * Take care of early registration before urcu_bp constructor.
554 */
555 _urcu_bp_init();
556
557 mutex_lock(&rcu_registry_lock);
558 add_thread();
559 mutex_unlock(&rcu_registry_lock);
560 end:
561 ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
562 if (ret)
563 abort();
564 }
565
566 void urcu_bp_register_thread(void)
567 {
568 if (caa_unlikely(!URCU_TLS(urcu_bp_reader)))
569 urcu_bp_register(); /* If not yet registered. */
570 }
571
572 /* Disable signals, take mutex, remove from registry */
573 static
574 void urcu_bp_unregister(struct rcu_reader *rcu_reader_reg)
575 {
576 sigset_t newmask, oldmask;
577 int ret;
578
579 ret = sigfillset(&newmask);
580 if (ret)
581 abort();
582 ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
583 if (ret)
584 abort();
585
586 mutex_lock(&rcu_registry_lock);
587 remove_thread(rcu_reader_reg);
588 mutex_unlock(&rcu_registry_lock);
589 ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
590 if (ret)
591 abort();
592 urcu_bp_exit();
593 }
594
595 /*
596 * Remove thread from the registry when it exits, and flag it as
597 * destroyed so garbage collection can take care of it.
598 */
599 static
600 void urcu_bp_thread_exit_notifier(void *rcu_key)
601 {
602 urcu_bp_unregister(rcu_key);
603 }
604
605 #ifdef CONFIG_RCU_FORCE_SYS_MEMBARRIER
606 static
607 void urcu_bp_sys_membarrier_status(bool available)
608 {
609 if (!available)
610 abort();
611 }
612 #else
613 static
614 void urcu_bp_sys_membarrier_status(bool available)
615 {
616 if (!available)
617 return;
618 urcu_bp_has_sys_membarrier = 1;
619 }
620 #endif
621
622 static
623 void urcu_bp_sys_membarrier_init(void)
624 {
625 bool available = false;
626 int mask;
627
628 mask = membarrier(MEMBARRIER_CMD_QUERY, 0);
629 if (mask >= 0) {
630 if (mask & MEMBARRIER_CMD_PRIVATE_EXPEDITED) {
631 if (membarrier(MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0))
632 urcu_die(errno);
633 available = true;
634 }
635 }
636 urcu_bp_sys_membarrier_status(available);
637 }
638
639 static
640 void _urcu_bp_init(void)
641 {
642 mutex_lock(&init_lock);
643 if (!urcu_bp_refcount++) {
644 int ret;
645
646 ret = pthread_key_create(&urcu_bp_key,
647 urcu_bp_thread_exit_notifier);
648 if (ret)
649 abort();
650 urcu_bp_sys_membarrier_init();
651 initialized = 1;
652 }
653 mutex_unlock(&init_lock);
654 }
655
656 static
657 void urcu_bp_exit(void)
658 {
659 urcu_call_rcu_exit();
660
661 mutex_lock(&init_lock);
662 if (!--urcu_bp_refcount) {
663 struct registry_chunk *chunk, *tmp;
664 int ret;
665
666 cds_list_for_each_entry_safe(chunk, tmp,
667 &registry_arena.chunk_list, node) {
668 munmap((void *) chunk, chunk->data_len
669 + sizeof(struct registry_chunk));
670 }
671 CDS_INIT_LIST_HEAD(&registry_arena.chunk_list);
672 ret = pthread_key_delete(urcu_bp_key);
673 if (ret)
674 abort();
675 }
676 mutex_unlock(&init_lock);
677 }
678
679 /*
680 * Holding the rcu_gp_lock and rcu_registry_lock across fork will make
681 * sure we fork() don't race with a concurrent thread executing with
682 * any of those locks held. This ensures that the registry and data
683 * protected by rcu_gp_lock are in a coherent state in the child.
684 */
685 void urcu_bp_before_fork(void)
686 {
687 sigset_t newmask, oldmask;
688 int ret;
689
690 ret = sigfillset(&newmask);
691 urcu_posix_assert(!ret);
692 ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
693 urcu_posix_assert(!ret);
694 mutex_lock(&rcu_gp_lock);
695 mutex_lock(&rcu_registry_lock);
696 saved_fork_signal_mask = oldmask;
697 }
698
699 void urcu_bp_after_fork_parent(void)
700 {
701 sigset_t oldmask;
702 int ret;
703
704 oldmask = saved_fork_signal_mask;
705 mutex_unlock(&rcu_registry_lock);
706 mutex_unlock(&rcu_gp_lock);
707 ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
708 urcu_posix_assert(!ret);
709 }
710
711 /*
712 * Prune all entries from registry except our own thread. Fits the Linux
713 * fork behavior. Called with rcu_gp_lock and rcu_registry_lock held.
714 */
715 static
716 void urcu_bp_prune_registry(void)
717 {
718 struct registry_chunk *chunk;
719 struct urcu_bp_reader *rcu_reader_reg;
720
721 cds_list_for_each_entry(chunk, &registry_arena.chunk_list, node) {
722 for (rcu_reader_reg = (struct urcu_bp_reader *) &chunk->data[0];
723 rcu_reader_reg < (struct urcu_bp_reader *) &chunk->data[chunk->data_len];
724 rcu_reader_reg++) {
725 if (!rcu_reader_reg->alloc)
726 continue;
727 if (rcu_reader_reg->tid == pthread_self())
728 continue;
729 cleanup_thread(chunk, rcu_reader_reg);
730 }
731 }
732 }
733
734 void urcu_bp_after_fork_child(void)
735 {
736 sigset_t oldmask;
737 int ret;
738
739 urcu_bp_prune_registry();
740 oldmask = saved_fork_signal_mask;
741 mutex_unlock(&rcu_registry_lock);
742 mutex_unlock(&rcu_gp_lock);
743 ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
744 urcu_posix_assert(!ret);
745 }
746
747 void *urcu_bp_dereference_sym(void *p)
748 {
749 return _rcu_dereference(p);
750 }
751
752 void *urcu_bp_set_pointer_sym(void **p, void *v)
753 {
754 cmm_wmb();
755 uatomic_set(p, v);
756 return v;
757 }
758
759 void *urcu_bp_xchg_pointer_sym(void **p, void *v)
760 {
761 cmm_wmb();
762 return uatomic_xchg(p, v);
763 }
764
765 void *urcu_bp_cmpxchg_pointer_sym(void **p, void *old, void *_new)
766 {
767 cmm_wmb();
768 return uatomic_cmpxchg(p, old, _new);
769 }
770
771 DEFINE_RCU_FLAVOR(rcu_flavor);
772
773 #include "urcu-call-rcu-impl.h"
774 #include "urcu-defer-impl.h"
775 #include "urcu-poll-impl.h"
This page took 0.054243 seconds and 5 git commands to generate.