tests: use SPDX identifiers
[urcu.git] / tests / common / debug-yield.h
CommitLineData
ce29b371
MJ
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
2650042a
MD
6#ifndef URCU_TESTS_DEBUG_YIELD_H
7#define URCU_TESTS_DEBUG_YIELD_H
8
9/*
2650042a
MD
10 * Userspace RCU library tests - Debugging header
11 *
2650042a
MD
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
094c8c59
MJ
20#include <compat-rand.h>
21
2650042a
MD
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
35extern unsigned int rcu_yield_active;
36extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield);
37
38#ifdef DEBUG_YIELD
39static 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
46static 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
53static inline void rcu_debug_yield_enable(unsigned int flags)
54{
55 rcu_yield_active |= flags;
56}
57
58static inline void rcu_debug_yield_disable(unsigned int flags)
59{
60 rcu_yield_active &= ~flags;
61}
62
63static 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 */
68static inline void rcu_debug_yield_read(void)
69{
70}
71
72static inline void rcu_debug_yield_write(void)
73{
74}
75
70469b43
MJ
76static inline void rcu_debug_yield_enable(
77 unsigned int flags __attribute__((unused)))
2650042a
MD
78{
79}
80
70469b43
MJ
81static inline void rcu_debug_yield_disable(
82 unsigned int flags __attribute__((unused)))
2650042a
MD
83{
84}
85
86static inline void rcu_debug_yield_init(void)
87{
88}
89#endif
90
91#endif /* URCU_TESTS_DEBUG_YIELD_H */
This page took 0.038341 seconds and 4 git commands to generate.