struct partition_resize_work *work;
int ret;
unsigned long thread, nr_threads;
+ sigset_t newmask, oldmask;
urcu_posix_assert(nr_cpus_mask != -1);
if (nr_cpus_mask < 0 || len < 2 * MIN_PARTITION_PER_THREAD)
dbg_printf("error allocating for resize, single-threading\n");
goto fallback;
}
+
+ ret = sigfillset(&newmask);
+ urcu_posix_assert(!ret);
+ ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
+ urcu_posix_assert(!ret);
+
for (thread = 0; thread < nr_threads; thread++) {
work[thread].ht = ht;
work[thread].i = i;
}
urcu_posix_assert(!ret);
}
+
+ ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
+ urcu_posix_assert(!ret);
+
for (thread = 0; thread < nr_threads; thread++) {
ret = pthread_join(work[thread].thread_id, NULL);
urcu_posix_assert(!ret);
.after_fork_child = cds_lfht_after_fork_child,
};
-/*
- * Block all signals for the workqueue worker thread to ensure we don't
- * disturb the application. The SIGRCU signal needs to be unblocked for
- * the urcu-signal flavor.
- */
-static void cds_lfht_worker_init(
- struct urcu_workqueue *workqueue __attribute__((unused)),
- void *priv __attribute__((unused)))
-{
- int ret;
- sigset_t mask;
-
- ret = sigfillset(&mask);
- if (ret)
- urcu_die(errno);
- ret = sigdelset(&mask, SIGRCU);
- if (ret)
- urcu_die(errno);
- ret = pthread_sigmask(SIG_SETMASK, &mask, NULL);
- if (ret)
- urcu_die(ret);
-}
-
static void cds_lfht_init_worker(const struct rcu_flavor_struct *flavor)
{
flavor->register_rculfhash_atfork(&cds_lfht_atfork);
if (cds_lfht_workqueue_user_count++)
goto end;
cds_lfht_workqueue = urcu_workqueue_create(0, -1, NULL,
- NULL, cds_lfht_worker_init, NULL, NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL);
end:
mutex_unlock(&cds_lfht_fork_mutex);
}
{
struct call_rcu_data *crdp;
int ret;
+ sigset_t newmask, oldmask;
crdp = malloc(sizeof(*crdp));
if (crdp == NULL)
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);
}
/*
static void start_defer_thread(void)
{
int ret;
+ sigset_t newmask, oldmask;
+
+ ret = sigfillset(&newmask);
+ urcu_posix_assert(!ret);
+ ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
+ urcu_posix_assert(!ret);
ret = pthread_create(&tid_defer, NULL, thr_defer, NULL);
urcu_posix_assert(!ret);
+
+ ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
+ urcu_posix_assert(!ret);
}
static void stop_defer_thread(void)
void __attribute__((constructor)) rcu_init(void);
void __attribute__((destructor)) rcu_exit(void);
+
+static DEFINE_URCU_TLS(int, rcu_signal_was_blocked);
#endif
/*
return _rcu_read_ongoing();
}
+#ifdef RCU_SIGNAL
+/*
+ * Make sure the signal used by the urcu-signal flavor is unblocked
+ * while the thread is registered.
+ */
+static
+void urcu_signal_unblock(void)
+{
+ sigset_t mask, oldmask;
+ int ret;
+
+ ret = sigemptyset(&mask);
+ urcu_posix_assert(!ret);
+ ret = sigaddset(&mask, SIGRCU);
+ urcu_posix_assert(!ret);
+ ret = pthread_sigmask(SIG_UNBLOCK, &mask, &oldmask);
+ urcu_posix_assert(!ret);
+ URCU_TLS(rcu_signal_was_blocked) = sigismember(&oldmask, SIGRCU);
+}
+
+static
+void urcu_signal_restore(void)
+{
+ sigset_t mask;
+ int ret;
+
+ if (!URCU_TLS(rcu_signal_was_blocked))
+ return;
+ ret = sigemptyset(&mask);
+ urcu_posix_assert(!ret);
+ ret = sigaddset(&mask, SIGRCU);
+ urcu_posix_assert(!ret);
+ ret = pthread_sigmask(SIG_BLOCK, &mask, NULL);
+ urcu_posix_assert(!ret);
+}
+#else
+static
+void urcu_signal_unblock(void) { }
+static
+void urcu_signal_restore(void) { }
+#endif
+
void rcu_register_thread(void)
{
+ urcu_signal_unblock();
+
URCU_TLS(rcu_reader).tid = pthread_self();
urcu_posix_assert(URCU_TLS(rcu_reader).need_mb == 0);
urcu_posix_assert(!(URCU_TLS(rcu_reader).ctr & URCU_GP_CTR_NEST_MASK));
URCU_TLS(rcu_reader).registered = 0;
cds_list_del(&URCU_TLS(rcu_reader).node);
mutex_unlock(&rcu_registry_lock);
+
+ urcu_signal_restore();
}
#ifdef RCU_MEMBARRIER
{
struct urcu_workqueue *workqueue;
int ret;
+ sigset_t newmask, oldmask;
workqueue = malloc(sizeof(*workqueue));
if (workqueue == NULL)
workqueue->cpu_affinity = cpu_affinity;
workqueue->loop_count = 0;
cmm_smp_mb(); /* Structure initialized before pointer is planted. */
+
+ ret = sigfillset(&newmask);
+ urcu_posix_assert(!ret);
+ ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
+ urcu_posix_assert(!ret);
+
ret = pthread_create(&workqueue->tid, NULL, workqueue_thread, workqueue);
if (ret) {
urcu_die(ret);
}
+
+ ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
+ urcu_posix_assert(!ret);
+
return workqueue;
}
void urcu_workqueue_create_worker(struct urcu_workqueue *workqueue)
{
int ret;
+ sigset_t newmask, oldmask;
/* Clear workqueue state from parent. */
workqueue->flags &= ~URCU_WORKQUEUE_PAUSED;
workqueue->flags &= ~URCU_WORKQUEUE_PAUSE;
workqueue->tid = 0;
+
+ ret = sigfillset(&newmask);
+ urcu_posix_assert(!ret);
+ ret = pthread_sigmask(SIG_BLOCK, &newmask, &oldmask);
+ urcu_posix_assert(!ret);
+
ret = pthread_create(&workqueue->tid, NULL, workqueue_thread, workqueue);
if (ret) {
urcu_die(ret);
}
+
+ ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
+ urcu_posix_assert(!ret);
}