fix: handle EINTR correctly in get_cpu_mask_from_sysfs
[urcu.git] / include / urcu / static / urcu-qsbr.h
index a6063e2de2de78f1f7a0da84f004b790825ad118..de798831bb5c1ac7aaa950351171b17c750053bb 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_QSBR_STATIC_H
 #define _URCU_QSBR_STATIC_H
 
 /*
- * urcu-qsbr-static.h
- *
  * Userspace RCU QSBR header.
  *
  * TO BE INCLUDED ONLY IN CODE THAT IS TO BE RECOMPILED ON EACH LIBURCU
  * RELEASE. See urcu.h for linking dynamically with the 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.
  */
 
@@ -35,6 +21,8 @@
 #include <unistd.h>
 #include <stdint.h>
 
+#include <urcu/annotate.h>
+#include <urcu/debug.h>
 #include <urcu/compiler.h>
 #include <urcu/arch.h>
 #include <urcu/system.h>
@@ -42,7 +30,6 @@
 #include <urcu/list.h>
 #include <urcu/futex.h>
 #include <urcu/tls-compat.h>
-#include <urcu/debug.h>
 #include <urcu/static/urcu-common.h>
 
 #ifdef __cplusplus
@@ -96,11 +83,14 @@ static inline void urcu_qsbr_wake_up_gp(void)
        }
 }
 
-static inline enum urcu_state urcu_qsbr_reader_state(unsigned long *ctr)
+static inline enum urcu_state urcu_qsbr_reader_state(unsigned long *ctr,
+                                               cmm_annotate_t *group)
 {
        unsigned long v;
 
-       v = CMM_LOAD_SHARED(*ctr);
+       v = uatomic_load(ctr, CMM_RELAXED);
+       cmm_annotate_group_mem_acquire(group, ctr);
+
        if (!v)
                return URCU_READER_INACTIVE;
        if (v == urcu_qsbr_gp.ctr)
@@ -117,7 +107,7 @@ static inline enum urcu_state urcu_qsbr_reader_state(unsigned long *ctr)
  */
 static inline void _urcu_qsbr_read_lock(void)
 {
-       urcu_assert(URCU_TLS(urcu_qsbr_reader).ctr);
+       urcu_assert_debug(URCU_TLS(urcu_qsbr_reader).ctr);
 }
 
 /*
@@ -129,7 +119,7 @@ static inline void _urcu_qsbr_read_lock(void)
  */
 static inline void _urcu_qsbr_read_unlock(void)
 {
-       urcu_assert(URCU_TLS(urcu_qsbr_reader).ctr);
+       urcu_assert_debug(URCU_TLS(urcu_qsbr_reader).ctr);
 }
 
 /*
@@ -155,9 +145,9 @@ static inline int _urcu_qsbr_read_ongoing(void)
  */
 static inline void _urcu_qsbr_quiescent_state_update_and_wakeup(unsigned long gp_ctr)
 {
-       cmm_smp_mb();
-       _CMM_STORE_SHARED(URCU_TLS(urcu_qsbr_reader).ctr, gp_ctr);
-       cmm_smp_mb();   /* write URCU_TLS(urcu_qsbr_reader).ctr before read futex */
+       uatomic_store(&URCU_TLS(urcu_qsbr_reader).ctr, gp_ctr, CMM_SEQ_CST);
+
+       /* write URCU_TLS(urcu_qsbr_reader).ctr before read futex */
        urcu_qsbr_wake_up_gp();
        cmm_smp_mb();
 }
@@ -178,8 +168,9 @@ static inline void _urcu_qsbr_quiescent_state(void)
 {
        unsigned long gp_ctr;
 
-       urcu_assert(URCU_TLS(urcu_qsbr_reader).registered);
-       if ((gp_ctr = CMM_LOAD_SHARED(urcu_qsbr_gp.ctr)) == URCU_TLS(urcu_qsbr_reader).ctr)
+       urcu_assert_debug(URCU_TLS(urcu_qsbr_reader).registered);
+       gp_ctr = uatomic_load(&urcu_qsbr_gp.ctr, CMM_RELAXED);
+       if (gp_ctr == URCU_TLS(urcu_qsbr_reader).ctr)
                return;
        _urcu_qsbr_quiescent_state_update_and_wakeup(gp_ctr);
 }
@@ -194,10 +185,9 @@ static inline void _urcu_qsbr_quiescent_state(void)
  */
 static inline void _urcu_qsbr_thread_offline(void)
 {
-       urcu_assert(URCU_TLS(urcu_qsbr_reader).registered);
-       cmm_smp_mb();
-       CMM_STORE_SHARED(URCU_TLS(urcu_qsbr_reader).ctr, 0);
-       cmm_smp_mb();   /* write URCU_TLS(urcu_qsbr_reader).ctr before read futex */
+       urcu_assert_debug(URCU_TLS(urcu_qsbr_reader).registered);
+       uatomic_store(&URCU_TLS(urcu_qsbr_reader).ctr, 0, CMM_SEQ_CST);
+       /* write URCU_TLS(urcu_qsbr_reader).ctr before read futex */
        urcu_qsbr_wake_up_gp();
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
 }
@@ -212,9 +202,14 @@ static inline void _urcu_qsbr_thread_offline(void)
  */
 static inline void _urcu_qsbr_thread_online(void)
 {
-       urcu_assert(URCU_TLS(urcu_qsbr_reader).registered);
+       unsigned long *pctr = &URCU_TLS(urcu_qsbr_reader).ctr;
+       unsigned long ctr;
+
+       urcu_assert_debug(URCU_TLS(urcu_qsbr_reader).registered);
        cmm_barrier();  /* Ensure the compiler does not reorder us with mutex */
-       _CMM_STORE_SHARED(URCU_TLS(urcu_qsbr_reader).ctr, CMM_LOAD_SHARED(urcu_qsbr_gp.ctr));
+       ctr = uatomic_load(&urcu_qsbr_gp.ctr, CMM_RELAXED);
+       cmm_annotate_mem_acquire(&urcu_qsbr_gp.ctr);
+       uatomic_store(pctr, ctr, CMM_RELAXED);
        cmm_smp_mb();
 }
 
This page took 0.024943 seconds and 4 git commands to generate.