From 9d335088c7c7eb6219e32ec9426d336f3a211a77 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 8 Feb 2009 19:21:34 -0500 Subject: [PATCH] Add randomness to yield debug test Add randomness to allow 1/2 odds that the yield will be done. This lets some paths go quickly and others not. Signed-off-by: Mathieu Desnoyers --- urcu.c | 3 ++- urcu.h | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/urcu.c b/urcu.c index 4362217..83d2fe4 100644 --- a/urcu.c +++ b/urcu.c @@ -33,7 +33,8 @@ struct reader_data { }; #ifdef DEBUG_YIELD -int yield_active; +unsigned int yield_active; +unsigned int __thread rand_yield; #endif static struct reader_data *reader_data; diff --git a/urcu.h b/urcu.h index 2aa3597..c77b26f 100644 --- a/urcu.h +++ b/urcu.h @@ -72,18 +72,26 @@ static inline void atomic_inc(int *v) #define YIELD_READ (1 << 0) #define YIELD_WRITE (1 << 1) -extern int yield_active; +extern unsigned int yield_active; +extern unsigned int __thread rand_yield; static inline void debug_yield_read(void) { if (yield_active & YIELD_READ) - sched_yield(); + if (rand_r(&rand_yield) & 0x1) + sched_yield(); } static inline void debug_yield_write(void) { if (yield_active & YIELD_WRITE) - sched_yield(); + if (rand_r(&rand_yield) & 0x1) + sched_yield(); +} + +static inline void debug_yield_init(void) +{ + rand_yield = time(NULL) ^ pthread_self(); } #else static inline void debug_yield_read(void) @@ -92,6 +100,11 @@ static inline void debug_yield_read(void) static inline void debug_yield_write(void) { +} + +static inline void debug_yield_init(void) +{ + } #endif -- 2.34.1