benchmark: Use uatomic for accessing global states
[urcu.git] / tests / benchmark / common-states.h
CommitLineData
9e4e7ad1
OD
1/* Common states for benchmarks. */
2
3#include <unistd.h>
4
5#include <urcu/uatomic.h>
6
7extern volatile int _test_go, _test_stop;
8
9static inline void complete_sleep(unsigned int seconds)
10{
11 while (seconds != 0) {
12 seconds = sleep(seconds);
13 }
14}
15
16static inline void begin_test(void)
17{
18 uatomic_store(&_test_go, 1, CMM_RELEASE);
19}
20
21static inline void end_test(void)
22{
23 uatomic_store(&_test_stop, 1, CMM_RELAXED);
24}
25
26static inline void test_for(unsigned int duration)
27{
28 begin_test();
29 complete_sleep(duration);
30 end_test();
31}
32
33static 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 */
43static inline int test_duration_write(void)
44{
45 return !uatomic_load(&_test_stop, CMM_RELAXED);
46}
47
48static inline int test_duration_read(void)
49{
50 return !uatomic_load(&_test_stop, CMM_RELAXED);
51}
This page took 0.024463 seconds and 4 git commands to generate.