| 1 | /* Common states for benchmarks. */ |
| 2 | |
| 3 | #include <unistd.h> |
| 4 | |
| 5 | #include <urcu/uatomic.h> |
| 6 | |
| 7 | extern volatile int _test_go, _test_stop; |
| 8 | |
| 9 | static inline void complete_sleep(unsigned int seconds) |
| 10 | { |
| 11 | while (seconds != 0) { |
| 12 | seconds = sleep(seconds); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | static inline void begin_test(void) |
| 17 | { |
| 18 | uatomic_store(&_test_go, 1, CMM_RELEASE); |
| 19 | } |
| 20 | |
| 21 | static inline void end_test(void) |
| 22 | { |
| 23 | uatomic_store(&_test_stop, 1, CMM_RELAXED); |
| 24 | } |
| 25 | |
| 26 | static inline void test_for(unsigned int duration) |
| 27 | { |
| 28 | begin_test(); |
| 29 | complete_sleep(duration); |
| 30 | end_test(); |
| 31 | } |
| 32 | |
| 33 | static inline void wait_until_go(void) |
| 34 | { |
| 35 | while (!uatomic_load(&_test_go, CMM_ACQUIRE)) |
| 36 | { |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * returns 0 if test should end. |
| 42 | */ |
| 43 | static inline int test_duration_write(void) |
| 44 | { |
| 45 | return !uatomic_load(&_test_stop, CMM_RELAXED); |
| 46 | } |
| 47 | |
| 48 | static inline int test_duration_read(void) |
| 49 | { |
| 50 | return !uatomic_load(&_test_stop, CMM_RELAXED); |
| 51 | } |