X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=urcu-call-rcu-impl.h;h=f9250e8b4129b925aeb7b47f609d3e91dd3f790d;hp=1ab49bc69da4eb753b264f90f5393cd22ce0fe98;hb=15cfbec77d2c573110cc936d5b33745d44207b50;hpb=59dc9e9db2c6d9e9039d7857194955c9b4d00c2d diff --git a/urcu-call-rcu-impl.h b/urcu-call-rcu-impl.h index 1ab49bc..f9250e8 100644 --- a/urcu-call-rcu-impl.h +++ b/urcu-call-rcu-impl.h @@ -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; @@ -600,6 +614,7 @@ void call_rcu_data_free(struct call_rcu_data *crdp) *cbs_endprev = cbs; uatomic_add(&default_call_rcu_data->qlen, uatomic_read(&crdp->qlen)); + wake_call_rcu_thread(default_call_rcu_data); } cds_list_del(&crdp->list);