+// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+// SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation.
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
/*
- * urcu.c
- *
* Userspace RCU library
*
- * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
* IBM's contributions to this file may be relicensed under LGPLv2 or later.
*/
static int init_done;
void __attribute__((constructor)) rcu_init(void);
-void __attribute__((destructor)) rcu_exit(void);
+
+static DEFINE_URCU_TLS(int, rcu_signal_was_blocked);
#endif
+void __attribute__((destructor)) rcu_exit(void);
+static void urcu_call_rcu_exit(void);
+
/*
* rcu_gp_lock ensures mutual exclusion between threads calling
* synchronize_rcu().
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
urcu_die(errno);
}
+/*
+ * Don't unregister the SIGRCU signal handler anymore, because
+ * call_rcu threads could still be using it shortly before the
+ * application exits.
+ * Assertion disabled because call_rcu threads are now rcu
+ * readers, and left running at exit.
+ * urcu_posix_assert(cds_list_empty(®istry));
+ */
+
+#endif /* #ifdef RCU_SIGNAL */
+
void rcu_exit(void)
{
- /*
- * Don't unregister the SIGRCU signal handler anymore, because
- * call_rcu threads could still be using it shortly before the
- * application exits.
- * Assertion disabled because call_rcu threads are now rcu
- * readers, and left running at exit.
- * urcu_posix_assert(cds_list_empty(®istry));
- */
+ urcu_call_rcu_exit();
}
-#endif /* #ifdef RCU_SIGNAL */
-
DEFINE_RCU_FLAVOR(rcu_flavor);
#include "urcu-call-rcu-impl.h"
#include "urcu-defer-impl.h"
+#include "urcu-poll-impl.h"