1 // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 // SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation.
4 // SPDX-License-Identifier: LGPL-2.1-or-later
6 #ifndef _URCU_COMMON_STATIC_H
7 #define _URCU_COMMON_STATIC_H
10 * Userspace RCU header.
12 * TO BE INCLUDED ONLY IN CODE THAT IS TO BE RECOMPILED ON EACH LIBURCU
13 * RELEASE. See urcu.h for linking dynamically with the userspace rcu library.
15 * IBM's contributions to this file may be relicensed under LGPLv2 or later.
23 #include <urcu/config.h>
24 #include <urcu/compiler.h>
25 #include <urcu/arch.h>
26 #include <urcu/system.h>
27 #include <urcu/uatomic.h>
28 #include <urcu/list.h>
29 #include <urcu/futex.h>
30 #include <urcu/tls-compat.h>
37 URCU_READER_ACTIVE_CURRENT
,
38 URCU_READER_ACTIVE_OLD
,
43 * The trick here is that URCU_GP_CTR_PHASE must be a multiple of 8 so
44 * we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower
47 #define URCU_GP_COUNT (1UL << 0)
48 /* Use the amount of bits equal to half of the architecture long size */
49 #define URCU_GP_CTR_PHASE (1UL << (sizeof(unsigned long) << 2))
50 #define URCU_GP_CTR_NEST_MASK (URCU_GP_CTR_PHASE - 1)
54 * Global grace period counter.
55 * Contains the current URCU_GP_CTR_PHASE.
56 * Also has a URCU_GP_COUNT of 1, to accelerate the reader fast path.
57 * Written to only by writer with mutex taken.
58 * Read by both writer and readers.
63 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
66 /* Data used by both reader and synchronize_rcu() */
69 /* Data used for registry */
70 struct cds_list_head node
__attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
72 /* Reader registered flag, for internal checks. */
73 unsigned int registered
:1;
77 * Wake-up waiting synchronize_rcu(). Called from many concurrent threads.
79 static inline void urcu_common_wake_up_gp(struct urcu_gp
*gp
)
81 if (caa_unlikely(uatomic_read(&gp
->futex
) == -1)) {
82 uatomic_set(&gp
->futex
, 0);
84 * Ignoring return value until we can make this function
85 * return something (because urcu_die() is not publicly
88 (void) futex_async(&gp
->futex
, FUTEX_WAKE
, 1,
93 static inline enum urcu_state
urcu_common_reader_state(struct urcu_gp
*gp
,
99 * Make sure both tests below are done on the same version of *value
100 * to insure consistency.
102 v
= CMM_LOAD_SHARED(*ctr
);
103 if (!(v
& URCU_GP_CTR_NEST_MASK
))
104 return URCU_READER_INACTIVE
;
105 if (!((v
^ gp
->ctr
) & URCU_GP_CTR_PHASE
))
106 return URCU_READER_ACTIVE_CURRENT
;
107 return URCU_READER_ACTIVE_OLD
;
114 #endif /* _URCU_COMMON_STATIC_H */