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_TESTS_DEBUG_YIELD_H
7 #define URCU_TESTS_DEBUG_YIELD_H
10 * Userspace RCU library tests - Debugging header
12 * IBM's contributions to this file may be relicensed under LGPLv2 or later.
20 #include <compat-rand.h>
22 #define RCU_YIELD_READ (1 << 0)
23 #define RCU_YIELD_WRITE (1 << 1)
27 extern unsigned int rcu_yield_active
;
28 extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield
);
31 static inline void rcu_debug_yield_read(void)
33 if (rcu_yield_active
& RCU_YIELD_READ
)
34 if (rand_r(&URCU_TLS(rcu_rand_yield
)) & 0x1)
35 usleep(rand_r(&URCU_TLS(rcu_rand_yield
)) % MAX_SLEEP
);
38 static inline void rcu_debug_yield_write(void)
40 if (rcu_yield_active
& RCU_YIELD_WRITE
)
41 if (rand_r(&URCU_TLS(rcu_rand_yield
)) & 0x1)
42 usleep(rand_r(&URCU_TLS(rcu_rand_yield
)) % MAX_SLEEP
);
45 static inline void rcu_debug_yield_enable(unsigned int flags
)
47 rcu_yield_active
|= flags
;
50 static inline void rcu_debug_yield_disable(unsigned int flags
)
52 rcu_yield_active
&= ~flags
;
55 static inline void rcu_debug_yield_init(void)
57 URCU_TLS(rcu_rand_yield
) = time(NULL
) ^ (unsigned long) pthread_self();
59 #else /* DEBUG_YIELD */
60 static inline void rcu_debug_yield_read(void)
64 static inline void rcu_debug_yield_write(void)
68 static inline void rcu_debug_yield_enable(
69 unsigned int flags
__attribute__((unused
)))
73 static inline void rcu_debug_yield_disable(
74 unsigned int flags
__attribute__((unused
)))
78 static inline void rcu_debug_yield_init(void)
83 #endif /* URCU_TESTS_DEBUG_YIELD_H */
This page took 0.047635 seconds and 4 git commands to generate.