1 #ifndef _URCU_COMMON_STATIC_H
2 #define _URCU_COMMON_STATIC_H
7 * Userspace RCU header.
9 * TO BE INCLUDED ONLY IN CODE THAT IS TO BE RECOMPILED ON EACH LIBURCU
10 * RELEASE. See urcu.h for linking dynamically with the userspace rcu library.
12 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 * IBM's contributions to this file may be relicensed under LGPLv2 or later.
37 #include <urcu/config.h>
38 #include <urcu/compiler.h>
39 #include <urcu/arch.h>
40 #include <urcu/system.h>
41 #include <urcu/uatomic.h>
42 #include <urcu/list.h>
43 #include <urcu/futex.h>
44 #include <urcu/tls-compat.h>
45 #include <urcu/debug.h>
52 URCU_READER_ACTIVE_CURRENT
,
53 URCU_READER_ACTIVE_OLD
,
58 * The trick here is that URCU_GP_CTR_PHASE must be a multiple of 8 so
59 * we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower
62 #define URCU_GP_COUNT (1UL << 0)
63 /* Use the amount of bits equal to half of the architecture long size */
64 #define URCU_GP_CTR_PHASE (1UL << (sizeof(unsigned long) << 2))
65 #define URCU_GP_CTR_NEST_MASK (URCU_GP_CTR_PHASE - 1)
69 * Global grace period counter.
70 * Contains the current URCU_GP_CTR_PHASE.
71 * Also has a URCU_GP_COUNT of 1, to accelerate the reader fast path.
72 * Written to only by writer with mutex taken.
73 * Read by both writer and readers.
78 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
81 /* Data used by both reader and synchronize_rcu() */
84 /* Data used for registry */
85 struct cds_list_head node
__attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
87 /* Reader registered flag, for internal checks. */
88 unsigned int registered
:1;
92 * Wake-up waiting synchronize_rcu(). Called from many concurrent threads.
94 static inline void urcu_common_wake_up_gp(struct urcu_gp
*gp
)
96 if (caa_unlikely(uatomic_read(&gp
->futex
) == -1)) {
97 uatomic_set(&gp
->futex
, 0);
99 * Ignoring return value until we can make this function
100 * return something (because urcu_die() is not publicly
103 (void) futex_async(&gp
->futex
, FUTEX_WAKE
, 1,
108 static inline enum urcu_state
urcu_common_reader_state(struct urcu_gp
*gp
,
114 * Make sure both tests below are done on the same version of *value
115 * to insure consistency.
117 v
= CMM_LOAD_SHARED(*ctr
);
118 if (!(v
& URCU_GP_CTR_NEST_MASK
))
119 return URCU_READER_INACTIVE
;
120 if (!((v
^ gp
->ctr
) & URCU_GP_CTR_PHASE
))
121 return URCU_READER_ACTIVE_CURRENT
;
122 return URCU_READER_ACTIVE_OLD
;
129 #endif /* _URCU_COMMON_STATIC_H */