X-Git-Url: http://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=src%2Furcu-call-rcu-impl.h;h=4562ba4704f067bda7960ef225de46aca7ed0f3b;hp=bfa53f8e09f920a833559ba7b334a04bf3cfcf47;hb=d0ec0ed2fcb5d67a28587dcb778606e64f5b7b83;hpb=ccacf27fd8d1af069016d7cf3a91f8995af08b8c diff --git a/src/urcu-call-rcu-impl.h b/src/urcu-call-rcu-impl.h index bfa53f8..4562ba4 100644 --- a/src/urcu-call-rcu-impl.h +++ b/src/urcu-call-rcu-impl.h @@ -99,6 +99,9 @@ static pthread_mutex_t call_rcu_mutex = PTHREAD_MUTEX_INITIALIZER; static struct call_rcu_data *default_call_rcu_data; +static struct urcu_atfork *registered_rculfhash_atfork; +static unsigned long registered_rculfhash_atfork_refcount; + /* * If the sched_getcpu() and sysconf(_SC_NPROCESSORS_CONF) calls are * available, then we can have call_rcu threads assigned to individual @@ -907,9 +910,14 @@ online: void call_rcu_before_fork(void) { struct call_rcu_data *crdp; + struct urcu_atfork *atfork; call_rcu_lock(&call_rcu_mutex); + atfork = registered_rculfhash_atfork; + if (atfork) + atfork->before_fork(atfork->priv); + cds_list_for_each_entry(crdp, &call_rcu_data_list, list) { uatomic_or(&crdp->flags, URCU_CALL_RCU_PAUSE); cmm_smp_mb__after_uatomic_or(); @@ -929,6 +937,7 @@ void call_rcu_before_fork(void) void call_rcu_after_fork_parent(void) { struct call_rcu_data *crdp; + struct urcu_atfork *atfork; cds_list_for_each_entry(crdp, &call_rcu_data_list, list) uatomic_and(&crdp->flags, ~URCU_CALL_RCU_PAUSE); @@ -936,6 +945,9 @@ void call_rcu_after_fork_parent(void) while ((uatomic_read(&crdp->flags) & URCU_CALL_RCU_PAUSED) != 0) (void) poll(NULL, 0, 1); } + atfork = registered_rculfhash_atfork; + if (atfork) + atfork->after_fork_parent(atfork->priv); call_rcu_unlock(&call_rcu_mutex); } @@ -947,10 +959,15 @@ void call_rcu_after_fork_parent(void) void call_rcu_after_fork_child(void) { struct call_rcu_data *crdp, *next; + struct urcu_atfork *atfork; /* Release the mutex. */ call_rcu_unlock(&call_rcu_mutex); + atfork = registered_rculfhash_atfork; + if (atfork) + atfork->after_fork_child(atfork->priv); + /* Do nothing when call_rcu() has not been used */ if (cds_list_empty(&call_rcu_data_list)) return; @@ -980,3 +997,23 @@ void call_rcu_after_fork_child(void) call_rcu_data_free(crdp); } } + +void urcu_register_rculfhash_atfork(struct urcu_atfork *atfork) +{ + call_rcu_lock(&call_rcu_mutex); + if (registered_rculfhash_atfork_refcount++) + goto end; + registered_rculfhash_atfork = atfork; +end: + call_rcu_unlock(&call_rcu_mutex); +} + +void urcu_unregister_rculfhash_atfork(struct urcu_atfork *atfork) +{ + call_rcu_lock(&call_rcu_mutex); + if (--registered_rculfhash_atfork_refcount) + goto end; + registered_rculfhash_atfork = NULL; +end: + call_rcu_unlock(&call_rcu_mutex); +}