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)
26 * Updates with RCU_SIGNAL are much slower. Account this in the delay.
29 /* maximum sleep delay, in us */
30 #define MAX_SLEEP 30000
35 extern unsigned int rcu_yield_active
;
36 extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield
);
39 static inline void rcu_debug_yield_read(void)
41 if (rcu_yield_active
& RCU_YIELD_READ
)
42 if (rand_r(&URCU_TLS(rcu_rand_yield
)) & 0x1)
43 usleep(rand_r(&URCU_TLS(rcu_rand_yield
)) % MAX_SLEEP
);
46 static inline void rcu_debug_yield_write(void)
48 if (rcu_yield_active
& RCU_YIELD_WRITE
)
49 if (rand_r(&URCU_TLS(rcu_rand_yield
)) & 0x1)
50 usleep(rand_r(&URCU_TLS(rcu_rand_yield
)) % MAX_SLEEP
);
53 static inline void rcu_debug_yield_enable(unsigned int flags
)
55 rcu_yield_active
|= flags
;
58 static inline void rcu_debug_yield_disable(unsigned int flags
)
60 rcu_yield_active
&= ~flags
;
63 static inline void rcu_debug_yield_init(void)
65 URCU_TLS(rcu_rand_yield
) = time(NULL
) ^ (unsigned long) pthread_self();
67 #else /* DEBUG_YIELD */
68 static inline void rcu_debug_yield_read(void)
72 static inline void rcu_debug_yield_write(void)
76 static inline void rcu_debug_yield_enable(
77 unsigned int flags
__attribute__((unused
)))
81 static inline void rcu_debug_yield_disable(
82 unsigned int flags
__attribute__((unused
)))
86 static inline void rcu_debug_yield_init(void)
91 #endif /* URCU_TESTS_DEBUG_YIELD_H */
This page took 0.032779 seconds and 5 git commands to generate.