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>
51 URCU_READER_ACTIVE_CURRENT
,
52 URCU_READER_ACTIVE_OLD
,
57 * The trick here is that URCU_GP_CTR_PHASE must be a multiple of 8 so
58 * we can use a full 8-bits, 16-bits or 32-bits bitmask for the lower
61 #define URCU_GP_COUNT (1UL << 0)
62 /* Use the amount of bits equal to half of the architecture long size */
63 #define URCU_GP_CTR_PHASE (1UL << (sizeof(unsigned long) << 2))
64 #define URCU_GP_CTR_NEST_MASK (URCU_GP_CTR_PHASE - 1)
68 * Global grace period counter.
69 * Contains the current URCU_GP_CTR_PHASE.
70 * Also has a URCU_GP_COUNT of 1, to accelerate the reader fast path.
71 * Written to only by writer with mutex taken.
72 * Read by both writer and readers.
77 } __attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
80 /* Data used by both reader and synchronize_rcu() */
83 /* Data used for registry */
84 struct cds_list_head node
__attribute__((aligned(CAA_CACHE_LINE_SIZE
)));
86 /* Reader registered flag, for internal checks. */
87 unsigned int registered
:1;
91 * Wake-up waiting synchronize_rcu(). Called from many concurrent threads.
93 static inline void urcu_common_wake_up_gp(struct urcu_gp
*gp
)
95 if (caa_unlikely(uatomic_read(&gp
->futex
) == -1)) {
96 uatomic_set(&gp
->futex
, 0);
98 * Ignoring return value until we can make this function
99 * return something (because urcu_die() is not publicly
102 (void) futex_async(&gp
->futex
, FUTEX_WAKE
, 1,
107 static inline enum urcu_state
urcu_common_reader_state(struct urcu_gp
*gp
,
113 * Make sure both tests below are done on the same version of *value
114 * to insure consistency.
116 v
= CMM_LOAD_SHARED(*ctr
);
117 if (!(v
& URCU_GP_CTR_NEST_MASK
))
118 return URCU_READER_INACTIVE
;
119 if (!((v
^ gp
->ctr
) & URCU_GP_CTR_PHASE
))
120 return URCU_READER_ACTIVE_CURRENT
;
121 return URCU_READER_ACTIVE_OLD
;
128 #endif /* _URCU_COMMON_STATIC_H */