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