X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=src%2Furcu-call-rcu-impl.h;h=1aba04a9a15e320fd9ae9a5ab2387fca643439db;hb=b047e7a793421e3ff1f5dca2b27c72751a1f4db4;hp=2ad02eb1b796614bd5ddfc1930b580277c0d09c7;hpb=98d705dd32be11b3f134b5aed87f9c201c028c10;p=userspace-rcu.git diff --git a/src/urcu-call-rcu-impl.h b/src/urcu-call-rcu-impl.h index 2ad02eb..1aba04a 100644 --- a/src/urcu-call-rcu-impl.h +++ b/src/urcu-call-rcu-impl.h @@ -44,6 +44,7 @@ #include #include "urcu-die.h" #include "urcu-utils.h" +#include "compat-smp.h" #define SET_AFFINITY_CHECK_PERIOD (1U << 8) /* 256 */ #define SET_AFFINITY_CHECK_PERIOD_MASK (SET_AFFINITY_CHECK_PERIOD - 1) @@ -101,7 +102,6 @@ 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 @@ -120,11 +120,11 @@ static unsigned long registered_rculfhash_atfork_refcount; */ static struct call_rcu_data **per_cpu_call_rcu_data; -static long maxcpus; +static long cpus_array_len; -static void maxcpus_reset(void) +static void cpus_array_len_reset(void) { - maxcpus = 0; + cpus_array_len = 0; } /* Allocate the array if it has not already been allocated. */ @@ -134,15 +134,15 @@ static void alloc_cpu_call_rcu_data(void) struct call_rcu_data **p; static int warned = 0; - if (maxcpus != 0) + if (cpus_array_len != 0) return; - maxcpus = sysconf(_SC_NPROCESSORS_CONF); - if (maxcpus <= 0) { + cpus_array_len = get_possible_cpus_array_len(); + if (cpus_array_len <= 0) { return; } - p = malloc(maxcpus * sizeof(*per_cpu_call_rcu_data)); + p = malloc(cpus_array_len * sizeof(*per_cpu_call_rcu_data)); if (p != NULL) { - memset(p, '\0', maxcpus * sizeof(*per_cpu_call_rcu_data)); + memset(p, '\0', cpus_array_len * sizeof(*per_cpu_call_rcu_data)); rcu_set_pointer(&per_cpu_call_rcu_data, p); } else { if (!warned) { @@ -160,9 +160,9 @@ static void alloc_cpu_call_rcu_data(void) * constant. */ static struct call_rcu_data **per_cpu_call_rcu_data = NULL; -static const long maxcpus = -1; +static const long cpus_array_len = -1; -static void maxcpus_reset(void) +static void cpus_array_len_reset(void) { } @@ -433,6 +433,7 @@ static void call_rcu_data_init(struct call_rcu_data **crdpp, { struct call_rcu_data *crdp; int ret; + sigset_t newmask, oldmask; crdp = malloc(sizeof(*crdp)); if (crdp == NULL) @@ -447,9 +448,18 @@ static void call_rcu_data_init(struct call_rcu_data **crdpp, crdp->gp_count = 0; cmm_smp_mb(); /* Structure initialized before pointer is planted. */ *crdpp = crdp; + + ret = sigfillset(&newmask); + urcu_posix_assert(!ret); + ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask); + urcu_posix_assert(!ret); + ret = pthread_create(&crdp->tid, NULL, call_rcu_thread, crdp); if (ret) urcu_die(ret); + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); } /* @@ -470,11 +480,11 @@ struct call_rcu_data *get_cpu_call_rcu_data(int cpu) pcpu_crdp = rcu_dereference(per_cpu_call_rcu_data); if (pcpu_crdp == NULL) return NULL; - if (!warned && maxcpus > 0 && (cpu < 0 || maxcpus <= cpu)) { + if (!warned && cpus_array_len > 0 && (cpu < 0 || cpus_array_len <= cpu)) { fprintf(stderr, "[error] liburcu: get CPU # out of range\n"); warned = 1; } - if (cpu < 0 || maxcpus <= cpu) + if (cpu < 0 || cpus_array_len <= cpu) return NULL; return rcu_dereference(pcpu_crdp[cpu]); } @@ -532,7 +542,7 @@ int set_cpu_call_rcu_data(int cpu, struct call_rcu_data *crdp) call_rcu_lock(&call_rcu_mutex); alloc_cpu_call_rcu_data(); - if (cpu < 0 || maxcpus <= cpu) { + if (cpu < 0 || cpus_array_len <= cpu) { if (!warned) { fprintf(stderr, "[error] liburcu: set CPU # out of range\n"); warned = 1; @@ -597,7 +607,7 @@ struct call_rcu_data *get_call_rcu_data(void) if (URCU_TLS(thread_call_rcu_data) != NULL) return URCU_TLS(thread_call_rcu_data); - if (maxcpus > 0) { + if (cpus_array_len > 0) { crd = get_cpu_call_rcu_data(urcu_sched_getcpu()); if (crd) return crd; @@ -648,7 +658,7 @@ int create_all_cpu_call_rcu_data(unsigned long flags) call_rcu_lock(&call_rcu_mutex); alloc_cpu_call_rcu_data(); call_rcu_unlock(&call_rcu_mutex); - if (maxcpus <= 0) { + if (cpus_array_len <= 0) { errno = EINVAL; return -EINVAL; } @@ -656,7 +666,7 @@ int create_all_cpu_call_rcu_data(unsigned long flags) errno = ENOMEM; return -ENOMEM; } - for (i = 0; i < maxcpus; i++) { + for (i = 0; i < cpus_array_len; i++) { call_rcu_lock(&call_rcu_mutex); if (get_cpu_call_rcu_data(i)) { call_rcu_unlock(&call_rcu_mutex); @@ -796,10 +806,10 @@ void free_all_cpu_call_rcu_data(void) struct call_rcu_data **crdp; static int warned = 0; - if (maxcpus <= 0) + if (cpus_array_len <= 0) return; - crdp = malloc(sizeof(*crdp) * maxcpus); + crdp = malloc(sizeof(*crdp) * cpus_array_len); if (!crdp) { if (!warned) { fprintf(stderr, "[error] liburcu: unable to allocate per-CPU pointer array\n"); @@ -808,7 +818,7 @@ void free_all_cpu_call_rcu_data(void) return; } - for (cpu = 0; cpu < maxcpus; cpu++) { + for (cpu = 0; cpu < cpus_array_len; cpu++) { crdp[cpu] = get_cpu_call_rcu_data(cpu); if (crdp[cpu] == NULL) continue; @@ -819,7 +829,7 @@ void free_all_cpu_call_rcu_data(void) * call_rcu_data to become quiescent. */ synchronize_rcu(); - for (cpu = 0; cpu < maxcpus; cpu++) { + for (cpu = 0; cpu < cpus_array_len; cpu++) { if (crdp[cpu] == NULL) continue; call_rcu_data_free(crdp[cpu]); @@ -997,7 +1007,7 @@ void call_rcu_after_fork_child(void) (void)get_default_call_rcu_data(); /* Cleanup call_rcu_data pointers before use */ - maxcpus_reset(); + cpus_array_len_reset(); free(per_cpu_call_rcu_data); rcu_set_pointer(&per_cpu_call_rcu_data, NULL); URCU_TLS(thread_call_rcu_data) = NULL; @@ -1017,20 +1027,20 @@ void call_rcu_after_fork_child(void) void urcu_register_rculfhash_atfork(struct urcu_atfork *atfork) { + if (CMM_LOAD_SHARED(registered_rculfhash_atfork)) + return; call_rcu_lock(&call_rcu_mutex); - if (registered_rculfhash_atfork_refcount++) - goto end; - registered_rculfhash_atfork = atfork; -end: + if (!registered_rculfhash_atfork) + registered_rculfhash_atfork = atfork; call_rcu_unlock(&call_rcu_mutex); } +/* + * This unregistration function is deprecated, meant only for internal + * use by rculfhash. + */ +__attribute__((noreturn)) void urcu_unregister_rculfhash_atfork(struct urcu_atfork *atfork __attribute__((unused))) { - call_rcu_lock(&call_rcu_mutex); - if (--registered_rculfhash_atfork_refcount) - goto end; - registered_rculfhash_atfork = NULL; -end: - call_rcu_unlock(&call_rcu_mutex); + urcu_die(EPERM); }