1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// SPDX-FileCopyrightText: 2009 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
// SPDX-FileCopyrightText: 2009 Paul E. McKenney, IBM Corporation.
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef URCU_TESTS_DEBUG_YIELD_H
#define URCU_TESTS_DEBUG_YIELD_H
/*
* Userspace RCU library tests - Debugging header
*
* IBM's contributions to this file may be relicensed under LGPLv2 or later.
*/
#include <sched.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <compat-rand.h>
#define RCU_YIELD_READ (1 << 0)
#define RCU_YIELD_WRITE (1 << 1)
#define MAX_SLEEP 50
extern unsigned int rcu_yield_active;
extern DECLARE_URCU_TLS(unsigned int, rcu_rand_yield);
#ifdef DEBUG_YIELD
static inline void rcu_debug_yield_read(void)
{
if (rcu_yield_active & RCU_YIELD_READ)
if (rand_r(&URCU_TLS(rcu_rand_yield)) & 0x1)
usleep(rand_r(&URCU_TLS(rcu_rand_yield)) % MAX_SLEEP);
}
static inline void rcu_debug_yield_write(void)
{
if (rcu_yield_active & RCU_YIELD_WRITE)
if (rand_r(&URCU_TLS(rcu_rand_yield)) & 0x1)
usleep(rand_r(&URCU_TLS(rcu_rand_yield)) % MAX_SLEEP);
}
static inline void rcu_debug_yield_enable(unsigned int flags)
{
rcu_yield_active |= flags;
}
static inline void rcu_debug_yield_disable(unsigned int flags)
{
rcu_yield_active &= ~flags;
}
static inline void rcu_debug_yield_init(void)
{
URCU_TLS(rcu_rand_yield) = time(NULL) ^ (unsigned long) pthread_self();
}
#else /* DEBUG_YIELD */
static inline void rcu_debug_yield_read(void)
{
}
static inline void rcu_debug_yield_write(void)
{
}
static inline void rcu_debug_yield_enable(
unsigned int flags __attribute__((__unused__)))
{
}
static inline void rcu_debug_yield_disable(
unsigned int flags __attribute__((__unused__)))
{
}
static inline void rcu_debug_yield_init(void)
{
}
#endif
#endif /* URCU_TESTS_DEBUG_YIELD_H */
|