tests: use SPDX identifiers
[urcu.git] / tests / common / debug-yield.h
1 // SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
2 // SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation.
3 //
4 // SPDX-License-Identifier: LGPL-2.1-or-later
5
6 #ifndef URCU_TESTS_DEBUG_YIELD_H
7 #define URCU_TESTS_DEBUG_YIELD_H
8
9 /*
10 * Userspace RCU library tests - Debugging header
11 *
12 * IBM's contributions to this file may be relicensed under LGPLv2 or later.
13 */
14
15 #include <sched.h>
16 #include <time.h>
17 #include <pthread.h>
18 #include <unistd.h>
19
20 #include <compat-rand.h>
21
22 #define RCU_YIELD_READ (1 << 0)
23 #define RCU_YIELD_WRITE (1 << 1)
24
25 /*
26 * Updates with RCU_SIGNAL are much slower. Account this in the delay.
27 */
28 #ifdef RCU_SIGNAL
29 /* maximum sleep delay, in us */
30 #define MAX_SLEEP 30000
31 #else
32 #define MAX_SLEEP 50
33 #endif
34
35 extern unsigned int rcu_yield_active;
36 extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield);
37
38 #ifdef DEBUG_YIELD
39 static inline void rcu_debug_yield_read(void)
40 {
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);
44 }
45
46 static inline void rcu_debug_yield_write(void)
47 {
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);
51 }
52
53 static inline void rcu_debug_yield_enable(unsigned int flags)
54 {
55 rcu_yield_active |= flags;
56 }
57
58 static inline void rcu_debug_yield_disable(unsigned int flags)
59 {
60 rcu_yield_active &= ~flags;
61 }
62
63 static inline void rcu_debug_yield_init(void)
64 {
65 URCU_TLS(rcu_rand_yield) = time(NULL) ^ (unsigned long) pthread_self();
66 }
67 #else /* DEBUG_YIELD */
68 static inline void rcu_debug_yield_read(void)
69 {
70 }
71
72 static inline void rcu_debug_yield_write(void)
73 {
74 }
75
76 static inline void rcu_debug_yield_enable(
77 unsigned int flags __attribute__((unused)))
78 {
79 }
80
81 static inline void rcu_debug_yield_disable(
82 unsigned int flags __attribute__((unused)))
83 {
84 }
85
86 static inline void rcu_debug_yield_init(void)
87 {
88 }
89 #endif
90
91 #endif /* URCU_TESTS_DEBUG_YIELD_H */
This page took 0.031291 seconds and 5 git commands to generate.