uatomic/x86: Remove redundant memory barriers
[urcu.git] / tests / benchmark / common-states.h
1 // SPDX-FileCopyrightText: 2023 Olivier Dion <odion@efficios.com>
2 //
3 // SPDX-License-Identifier: GPL-2.0-or-later
4
5 /* Common states for benchmarks. */
6
7 #include <unistd.h>
8
9 #include <urcu/uatomic.h>
10
11 extern volatile int _test_go, _test_stop;
12
13 static inline void complete_sleep(unsigned int seconds)
14 {
15 while (seconds != 0) {
16 seconds = sleep(seconds);
17 }
18 }
19
20 static inline void begin_test(void)
21 {
22 uatomic_store(&_test_go, 1, CMM_RELEASE);
23 }
24
25 static inline void end_test(void)
26 {
27 uatomic_store(&_test_stop, 1, CMM_RELAXED);
28 }
29
30 static inline void test_for(unsigned int duration)
31 {
32 begin_test();
33 complete_sleep(duration);
34 end_test();
35 }
36
37 static inline void wait_until_go(void)
38 {
39 while (!uatomic_load(&_test_go, CMM_ACQUIRE))
40 {
41 }
42 }
43
44 /*
45 * returns 0 if test should end.
46 */
47 static inline int test_duration_write(void)
48 {
49 return !uatomic_load(&_test_stop, CMM_RELAXED);
50 }
51
52 static inline int test_duration_read(void)
53 {
54 return !uatomic_load(&_test_stop, CMM_RELAXED);
55 }
This page took 0.029645 seconds and 4 git commands to generate.