X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Fbenchmark%2Fcommon-states.h;fp=tests%2Fbenchmark%2Fcommon-states.h;h=dfbbfe5b42beba3c6f2349e7e6044387039c2939;hp=0000000000000000000000000000000000000000;hb=9e4e7ad18c86159520b330fab94b93f7ab6d221c;hpb=c8c32a5208d6e624f9ae9466196e355269c611d5 diff --git a/tests/benchmark/common-states.h b/tests/benchmark/common-states.h new file mode 100644 index 0000000..dfbbfe5 --- /dev/null +++ b/tests/benchmark/common-states.h @@ -0,0 +1,51 @@ +/* Common states for benchmarks. */ + +#include + +#include + +extern volatile int _test_go, _test_stop; + +static inline void complete_sleep(unsigned int seconds) +{ + while (seconds != 0) { + seconds = sleep(seconds); + } +} + +static inline void begin_test(void) +{ + uatomic_store(&_test_go, 1, CMM_RELEASE); +} + +static inline void end_test(void) +{ + uatomic_store(&_test_stop, 1, CMM_RELAXED); +} + +static inline void test_for(unsigned int duration) +{ + begin_test(); + complete_sleep(duration); + end_test(); +} + +static inline void wait_until_go(void) +{ + while (!uatomic_load(&_test_go, CMM_ACQUIRE)) + { + } +} + +/* + * returns 0 if test should end. + */ +static inline int test_duration_write(void) +{ + return !uatomic_load(&_test_stop, CMM_RELAXED); +} + +static inline int test_duration_read(void) +{ + return !uatomic_load(&_test_stop, CMM_RELAXED); +}