uatomic/x86: Remove redundant memory barriers
[urcu.git] / src / urcu-defer-impl.h
index d25e9b93f4dc17e8f1e6ee986ad04cdca366527f..a180c4875bf173ea70f70d93aa6d17f998919229 100644 (file)
@@ -1,31 +1,17 @@
+// 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
+
 #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 <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.
  */
 
@@ -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);
@@ -401,8 +395,18 @@ void defer_rcu(void (*fct)(void *p), void *p)
 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);
+       if (ret)
+               urcu_die(ret);
+
+       ret = pthread_sigmask(SIG_SETMASK, &oldmask, NULL);
        urcu_posix_assert(!ret);
 }
 
This page took 0.023276 seconds and 4 git commands to generate.