urcu,call_rcu: avoid create call_rcu_data for child when unneed
[urcu.git] / urcu-call-rcu-impl.h
index 1ab49bc69da4eb753b264f90f5393cd22ce0fe98..d964c474156473c43b6bbff4f69abf5d06355e57 100644 (file)
@@ -396,12 +396,21 @@ int set_cpu_call_rcu_data(int cpu, struct call_rcu_data *crdp)
                errno = EINVAL;
                return -EINVAL;
        }
-       call_rcu_unlock(&call_rcu_mutex);
+
        if (per_cpu_call_rcu_data == NULL) {
+               call_rcu_unlock(&call_rcu_mutex);
                errno = ENOMEM;
                return -ENOMEM;
        }
+
+       if (per_cpu_call_rcu_data[cpu] != NULL && crdp != NULL) {
+               call_rcu_unlock(&call_rcu_mutex);
+               errno = EEXIST;
+               return -EEXIST;
+       }
+
        per_cpu_call_rcu_data[cpu] = crdp;
+       call_rcu_unlock(&call_rcu_mutex);
        return 0;
 }
 
@@ -513,8 +522,13 @@ int create_all_cpu_call_rcu_data(unsigned long flags)
                }
                call_rcu_unlock(&call_rcu_mutex);
                if ((ret = set_cpu_call_rcu_data(i, crdp)) != 0) {
-                       /* FIXME: Leaks crdp for now. */
-                       return ret; /* Can happen on race. */
+                       call_rcu_data_free(crdp);
+
+                       /* it has been created by other thread */
+                       if (ret == -EEXIST)
+                               continue;
+
+                       return ret;
                }
        }
        return 0;
@@ -595,14 +609,20 @@ void call_rcu_data_free(struct call_rcu_data *crdp)
                _CMM_STORE_SHARED(crdp->cbs.head, NULL);
                cbs_tail = (struct cds_wfq_node **)
                        uatomic_xchg(&crdp->cbs.tail, &crdp->cbs.head);
+               /* Create default call rcu data if need be */
+               (void) get_default_call_rcu_data();
                cbs_endprev = (struct cds_wfq_node **)
                        uatomic_xchg(&default_call_rcu_data, cbs_tail);
                *cbs_endprev = cbs;
                uatomic_add(&default_call_rcu_data->qlen,
                            uatomic_read(&crdp->qlen));
+               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);
 }
 
@@ -657,6 +677,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.
This page took 0.023089 seconds and 4 git commands to generate.