X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Furcu-qsbr.c;h=98e27655031ac1afe8985ae5b9089d5d968dfb7c;hb=acdb82a20ba20467b89c67aa44ca03da610513a9;hp=40c0fbdb35519983186c67615f8c285a691f91d8;hpb=a0ec6d9b6b67e37fc81c98e04008907bc500cde8;p=userspace-rcu.git diff --git a/src/urcu-qsbr.c b/src/urcu-qsbr.c index 40c0fbd..98e2765 100644 --- a/src/urcu-qsbr.c +++ b/src/urcu-qsbr.c @@ -1,25 +1,11 @@ +// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers +// SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation. +// +// SPDX-License-Identifier: LGPL-2.1-or-later + /* - * urcu-qsbr.c - * * Userspace RCU QSBR 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. */ @@ -28,13 +14,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #define BUILD_QSBR_LIB @@ -53,6 +39,7 @@ #define _LGPL_SOURCE void __attribute__((destructor)) urcu_qsbr_exit(void); +static void urcu_call_rcu_exit(void); /* * rcu_gp_lock ensures mutual exclusion between threads calling @@ -123,17 +110,25 @@ static void wait_gp(void) { /* Read reader_gp before read futex */ cmm_smp_rmb(); - if (uatomic_read(&urcu_qsbr_gp.futex) != -1) - return; - while (futex_noasync(&urcu_qsbr_gp.futex, FUTEX_WAIT, -1, - NULL, NULL, 0)) { + while (uatomic_read(&urcu_qsbr_gp.futex) == -1) { + if (!futex_noasync(&urcu_qsbr_gp.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); @@ -278,7 +273,7 @@ void urcu_qsbr_synchronize_rcu(void) /* * Wait for readers to observe original parity or be quiescent. * wait_for_readers() can release and grab again rcu_registry_lock - * interally. + * internally. */ wait_for_readers(®istry, &cur_snap_readers, &qsreaders); @@ -321,7 +316,7 @@ void urcu_qsbr_synchronize_rcu(void) /* * Wait for readers to observe new parity or be quiescent. * wait_for_readers() can release and grab again rcu_registry_lock - * interally. + * internally. */ wait_for_readers(&cur_snap_readers, NULL, &qsreaders); @@ -410,7 +405,7 @@ void urcu_qsbr_synchronize_rcu(void) /* * Wait for readers to observe new count of be quiescent. * wait_for_readers() can release and grab again rcu_registry_lock - * interally. + * internally. */ wait_for_readers(®istry, NULL, &qsreaders); @@ -470,10 +465,10 @@ void urcu_qsbr_thread_online(void) void urcu_qsbr_register_thread(void) { URCU_TLS(urcu_qsbr_reader).tid = pthread_self(); - assert(URCU_TLS(urcu_qsbr_reader).ctr == 0); + urcu_posix_assert(URCU_TLS(urcu_qsbr_reader).ctr == 0); mutex_lock(&rcu_registry_lock); - assert(!URCU_TLS(urcu_qsbr_reader).registered); + urcu_posix_assert(!URCU_TLS(urcu_qsbr_reader).registered); URCU_TLS(urcu_qsbr_reader).registered = 1; cds_list_add(&URCU_TLS(urcu_qsbr_reader).node, ®istry); mutex_unlock(&rcu_registry_lock); @@ -487,7 +482,7 @@ void urcu_qsbr_unregister_thread(void) * with a waiting writer. */ _urcu_qsbr_thread_offline(); - assert(URCU_TLS(urcu_qsbr_reader).registered); + urcu_posix_assert(URCU_TLS(urcu_qsbr_reader).registered); URCU_TLS(urcu_qsbr_reader).registered = 0; mutex_lock(&rcu_registry_lock); cds_list_del(&URCU_TLS(urcu_qsbr_reader).node); @@ -499,11 +494,13 @@ void urcu_qsbr_exit(void) /* * Assertion disabled because call_rcu threads are now rcu * readers, and left running at exit. - * assert(cds_list_empty(®istry)); + * urcu_posix_assert(cds_list_empty(®istry)); */ + urcu_call_rcu_exit(); } DEFINE_RCU_FLAVOR(rcu_flavor); #include "urcu-call-rcu-impl.h" #include "urcu-defer-impl.h" +#include "urcu-poll-impl.h"