OLD | NEW |
---|---|
(Empty) | |
1 // This aims to test that all the atomic RMW instructions and compare and swap | |
2 // work across the allowed atomic types. This uses the __sync_* builtins | |
3 // to test the atomic operations. | |
4 | |
5 #include <stdint.h> | |
6 | |
7 #include <cstdlib> | |
8 | |
9 #include "test_sync_atomic.h" | |
10 | |
11 #define X(inst, type) \ | |
12 type test_##inst(bool fetch_first, volatile type *ptr, type a) { \ | |
13 if (fetch_first) return __sync_fetch_and_##inst(ptr, a); \ | |
Jim Stichnoth
2014/07/08 04:50:19
Violation (here and below) of Google style guide.
jvoung (off chromium)
2014/07/08 18:14:06
Done.
| |
14 else return __sync_##inst##_and_fetch(ptr, a); \ | |
15 } \ | |
16 type test_alloca_##inst(bool fetch, volatile type *ptr, type a) { \ | |
17 const size_t buf_size = 8; \ | |
18 type buf[buf_size]; \ | |
19 for (size_t i = 0; i < buf_size; ++i) { \ | |
20 if (fetch) buf[i] = __sync_fetch_and_##inst(ptr, a); \ | |
21 else buf[i] = __sync_##inst##_and_fetch(ptr, a); \ | |
22 } \ | |
23 type sum = 0; \ | |
24 for (size_t i = 0; i < buf_size; ++i) { \ | |
25 sum += buf[i]; \ | |
26 } \ | |
27 return sum; \ | |
28 } \ | |
29 type test_const_##inst(bool fetch, volatile type *ptr, type ign) { \ | |
30 if (fetch) return __sync_fetch_and_##inst(ptr, 42); \ | |
31 else return __sync_##inst##_and_fetch(ptr, 99); \ | |
32 } | |
33 | |
34 FOR_ALL_RMWOP_TYPES(X) | |
35 #undef X | |
36 | |
37 #define X(type) \ | |
38 type test_val_cmp_swap(volatile type *ptr, type oldval, type newval) { \ | |
39 return __sync_val_compare_and_swap(ptr, oldval, newval); \ | |
40 } | |
41 | |
42 ATOMIC_TYPE_TABLE | |
43 #undef X | |
OLD | NEW |