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/annotate.h>
24 #include <urcu/config.h>
25 #include <urcu/compiler.h>
26 #include <urcu/arch.h>
27 #include <urcu/system.h>
28 #include <urcu/uatomic.h>
29 #include <urcu/list.h>
30 #include <urcu/futex.h>
31 #include <urcu/tls-compat.h>
38 URCU_READER_ACTIVE_CURRENT
,
39 URCU_READER_ACTIVE_OLD
,
44 * The trick here is that URCU_GP_CTR_PHASE must be a multiple of 8 so
45 * we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower
48 #define URCU_GP_COUNT (1UL << 0)
49 /* Use the amount of bits equal to half of the architecture long size */
50 #define URCU_GP_CTR_PHASE (1UL << (sizeof(unsigned long) << 2))
51 #define URCU_GP_CTR_NEST_MASK (URCU_GP_CTR_PHASE - 1)
55 * Global grace period counter.
56 * Contains the current URCU_GP_CTR_PHASE.
57 * Also has a URCU_GP_COUNT of 1, to accelerate the reader fast path.
58 * Written to only by writer with mutex taken.
59 * Read by both writer and readers.
64 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
67 /* Data used by both reader and synchronize_rcu() */
70 /* Data used for registry */
71 struct cds_list_head node
__attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
73 /* Reader registered flag, for internal checks. */
74 unsigned int registered
:1;
78 * Wake-up waiting synchronize_rcu(). Called from many concurrent threads.
80 static inline void urcu_common_wake_up_gp(struct urcu_gp
*gp
)
82 if (caa_unlikely(uatomic_read(&gp
->futex
) == -1)) {
83 uatomic_set(&gp
->futex
, 0);
85 * Ignoring return value until we can make this function
86 * return something (because urcu_die() is not publicly
89 (void) futex_async(&gp
->futex
, FUTEX_WAKE
, 1,
94 static inline enum urcu_state
urcu_common_reader_state(struct urcu_gp
*gp
,
96 cmm_annotate_t
*group
)
101 * Make sure both tests below are done on the same version of *value
102 * to insure consistency.
104 v
= uatomic_load(ctr
, CMM_RELAXED
);
105 cmm_annotate_group_mem_acquire(group
, ctr
);
107 if (!(v
& URCU_GP_CTR_NEST_MASK
))
108 return URCU_READER_INACTIVE
;
109 if (!((v
^ gp
->ctr
) & URCU_GP_CTR_PHASE
))
110 return URCU_READER_ACTIVE_CURRENT
;
111 return URCU_READER_ACTIVE_OLD
;
118 #endif /* _URCU_COMMON_STATIC_H */