1 #ifndef URCU_TESTS_DEBUG_YIELD_H
2 #define URCU_TESTS_DEBUG_YIELD_H
7 * Userspace RCU library tests - Debugging header
9 * Copyright (c) 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Copyright (c) 2009 Paul E. McKenney, IBM Corporation.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 * IBM's contributions to this file may be relicensed under LGPLv2 or later.
34 #include <compat-rand.h>
36 #define RCU_YIELD_READ (1 << 0)
37 #define RCU_YIELD_WRITE (1 << 1)
40 * Updates with RCU_SIGNAL are much slower. Account this in the delay.
43 /* maximum sleep delay, in us */
44 #define MAX_SLEEP 30000
49 extern unsigned int rcu_yield_active
;
50 extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield
);
53 static inline void rcu_debug_yield_read(void)
55 if (rcu_yield_active
& RCU_YIELD_READ
)
56 if (rand_r(&URCU_TLS(rcu_rand_yield
)) & 0x1)
57 usleep(rand_r(&URCU_TLS(rcu_rand_yield
)) % MAX_SLEEP
);
60 static inline void rcu_debug_yield_write(void)
62 if (rcu_yield_active
& RCU_YIELD_WRITE
)
63 if (rand_r(&URCU_TLS(rcu_rand_yield
)) & 0x1)
64 usleep(rand_r(&URCU_TLS(rcu_rand_yield
)) % MAX_SLEEP
);
67 static inline void rcu_debug_yield_enable(unsigned int flags
)
69 rcu_yield_active
|= flags
;
72 static inline void rcu_debug_yield_disable(unsigned int flags
)
74 rcu_yield_active
&= ~flags
;
77 static inline void rcu_debug_yield_init(void)
79 URCU_TLS(rcu_rand_yield
) = time(NULL
) ^ (unsigned long) pthread_self();
81 #else /* DEBUG_YIELD */
82 static inline void rcu_debug_yield_read(void)
86 static inline void rcu_debug_yield_write(void)
90 static inline void rcu_debug_yield_enable(
91 unsigned int flags
__attribute__((unused
)))
95 static inline void rcu_debug_yield_disable(
96 unsigned int flags
__attribute__((unused
)))
100 static inline void rcu_debug_yield_init(void)
105 #endif /* URCU_TESTS_DEBUG_YIELD_H */
This page took 0.031723 seconds and 4 git commands to generate.