urcu,call_rcu: Cleanup call_rcu_data pointers before use in child
[urcu.git] / urcu-call-rcu-impl.h
index 3e947af2fd84bfd6c6843788d9f31a5ff720b876..0a47d969a4e8d3f50438fc69bbede379e6715c50 100644 (file)
@@ -88,6 +88,11 @@ static struct call_rcu_data *default_call_rcu_data;
 static struct call_rcu_data **per_cpu_call_rcu_data;
 static long maxcpus;
 
+static void maxcpus_reset(void)
+{
+       maxcpus = 0;
+}
+
 /* Allocate the array if it has not already been allocated. */
 
 static void alloc_cpu_call_rcu_data(void)
@@ -123,6 +128,10 @@ static void alloc_cpu_call_rcu_data(void)
 static struct call_rcu_data **per_cpu_call_rcu_data = NULL;
 static const long maxcpus = -1;
 
+static void maxcpus_reset(void)
+{
+}
+
 static void alloc_cpu_call_rcu_data(void)
 {
 }
@@ -619,7 +628,10 @@ void call_rcu_data_free(struct call_rcu_data *crdp)
                wake_call_rcu_thread(default_call_rcu_data);
        }
 
+       call_rcu_lock(&call_rcu_mutex);
        cds_list_del(&crdp->list);
+       call_rcu_unlock(&call_rcu_mutex);
+
        free(crdp);
 }
 
@@ -674,6 +686,10 @@ void call_rcu_after_fork_child(void)
        /* Release the mutex. */
        call_rcu_unlock(&call_rcu_mutex);
 
+       /* Do nothing when call_rcu() has not been used */
+       if (cds_list_empty(&call_rcu_data_list))
+               return;
+
        /*
         * Allocate a new default call_rcu_data structure in order
         * to get a working call_rcu thread to go with it.
@@ -681,6 +697,12 @@ void call_rcu_after_fork_child(void)
        default_call_rcu_data = NULL;
        (void)get_default_call_rcu_data();
 
+       /* Cleanup call_rcu_data pointers before use */
+       maxcpus_reset();
+       free(per_cpu_call_rcu_data);
+       per_cpu_call_rcu_data = NULL;
+       thread_call_rcu_data = NULL;
+
        /* Dispose of all of the rest of the call_rcu_data structures. */
        cds_list_for_each_entry_safe(crdp, next, &call_rcu_data_list, list) {
                if (crdp == default_call_rcu_data)
This page took 0.024087 seconds and 4 git commands to generate.