X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=src%2Furcu-defer-impl.h;h=8b5ad972421d52f523f18146a3a1a068c2bcb661;hp=969231f8b552aa733dc5aedd91c8fd86ece5981c;hb=HEAD;hpb=70469b43316ecc8d6053550504858ad8a8ef9b16 diff --git a/src/urcu-defer-impl.h b/src/urcu-defer-impl.h index 969231f..a180c48 100644 --- a/src/urcu-defer-impl.h +++ b/src/urcu-defer-impl.h @@ -1,31 +1,17 @@ +// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers +// SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation. +// +// SPDX-License-Identifier: LGPL-2.1-or-later + #ifndef _URCU_DEFER_IMPL_H #define _URCU_DEFER_IMPL_H /* - * urcu-defer-impl.h - * * Userspace RCU header - memory reclamation. * * TO BE INCLUDED ONLY FROM URCU LIBRARY CODE. See urcu-defer.h for linking * dynamically with the userspace rcu reclamation library. * - * Copyright (c) 2009 Mathieu Desnoyers - * 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. */ @@ -33,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -43,6 +28,7 @@ #include "urcu/futex.h" +#include #include #include #include @@ -194,17 +180,25 @@ static void wait_defer(void) uatomic_set(&defer_thread_futex, 0); } else { cmm_smp_rmb(); /* Read queue before read futex */ - if (uatomic_read(&defer_thread_futex) != -1) - return; - while (futex_noasync(&defer_thread_futex, FUTEX_WAIT, -1, - NULL, NULL, 0)) { + while (uatomic_read(&defer_thread_futex) == -1) { + if (!futex_noasync(&defer_thread_futex, FUTEX_WAIT, -1, NULL, NULL, 0)) { + /* + * Prior queued wakeups queued by unrelated code + * using the same address can cause futex wait to + * return 0 even through the futex value is still + * -1 (spurious wakeups). Check the value again + * in user-space to validate whether it really + * differs from -1. + */ + continue; + } switch (errno) { - case EWOULDBLOCK: + case EAGAIN: /* Value already changed. */ return; case EINTR: /* Retry if interrupted by signal. */ - break; /* Get out of switch. */ + break; /* Get out of switch. Check again. */ default: /* Unexpected error. */ urcu_die(errno); @@ -265,8 +259,6 @@ void rcu_defer_barrier_thread(void) _rcu_defer_barrier_thread(); mutex_unlock(&rcu_defer_mutex); } -URCU_ATTR_ALIAS(urcu_stringify(rcu_defer_barrier_thread)) -void alias_rcu_defer_barrier_thread(); /* * rcu_defer_barrier - Execute all queued rcu callbacks. @@ -307,8 +299,6 @@ void rcu_defer_barrier(void) end: mutex_unlock(&rcu_defer_mutex); } -URCU_ATTR_ALIAS(urcu_stringify(rcu_defer_barrier)) -void alias_rcu_defer_barrier(); /* * _defer_rcu - Queue a RCU callback. @@ -329,9 +319,9 @@ static void _defer_rcu(void (*fct)(void *p), void *p) * Worse-case: must allow 2 supplementary entries for fct pointer. */ if (caa_unlikely(head - tail >= DEFER_QUEUE_SIZE - 2)) { - assert(head - tail <= DEFER_QUEUE_SIZE); + urcu_posix_assert(head - tail <= DEFER_QUEUE_SIZE); rcu_defer_barrier_thread(); - assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0); + urcu_posix_assert(head - CMM_LOAD_SHARED(URCU_TLS(defer_queue).tail) == 0); } /* @@ -401,14 +391,23 @@ void defer_rcu(void (*fct)(void *p), void *p) { _defer_rcu(fct, p); } -URCU_ATTR_ALIAS(urcu_stringify(defer_rcu)) void alias_defer_rcu(); 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); - assert(!ret); + if (ret) + urcu_die(ret); + + ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL); + urcu_posix_assert(!ret); } static void stop_defer_thread(void) @@ -422,19 +421,19 @@ static void stop_defer_thread(void) wake_up_defer(); ret = pthread_join(tid_defer, &tret); - assert(!ret); + urcu_posix_assert(!ret); CMM_STORE_SHARED(defer_thread_stop, 0); /* defer thread should always exit when futex value is 0 */ - assert(uatomic_read(&defer_thread_futex) == 0); + urcu_posix_assert(uatomic_read(&defer_thread_futex) == 0); } int rcu_defer_register_thread(void) { int was_empty; - assert(URCU_TLS(defer_queue).last_head == 0); - assert(URCU_TLS(defer_queue).q == NULL); + urcu_posix_assert(URCU_TLS(defer_queue).last_head == 0); + urcu_posix_assert(URCU_TLS(defer_queue).q == NULL); URCU_TLS(defer_queue).q = malloc(sizeof(void *) * DEFER_QUEUE_SIZE); if (!URCU_TLS(defer_queue).q) return -ENOMEM; @@ -450,8 +449,6 @@ int rcu_defer_register_thread(void) mutex_unlock(&defer_thread_mutex); return 0; } -URCU_ATTR_ALIAS(urcu_stringify(rcu_defer_register_thread)) -int alias_rcu_defer_register_thread(); void rcu_defer_unregister_thread(void) { @@ -470,14 +467,10 @@ void rcu_defer_unregister_thread(void) stop_defer_thread(); mutex_unlock(&defer_thread_mutex); } -URCU_ATTR_ALIAS(urcu_stringify(rcu_defer_unregister_thread)) -void alias_rcu_defer_unregister_thread(); void rcu_defer_exit(void) { - assert(cds_list_empty(®istry_defer)); + urcu_posix_assert(cds_list_empty(®istry_defer)); } -URCU_ATTR_ALIAS(urcu_stringify(rcu_defer_exit)) -void alias_rcu_defer_exit(); #endif /* _URCU_DEFER_IMPL_H */