OLD | NEW |
1 //===- subzero/crosstest/test_sync_atomic.cpp - Implementation for tests --===// | 1 //===- subzero/crosstest/test_sync_atomic.cpp - Implementation for tests --===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This aims to test that all the atomic RMW instructions and compare and swap | 10 // This aims to test that all the atomic RMW instructions and compare and swap |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (fetch) { \ | 47 if (fetch) { \ |
48 return __sync_fetch_and_##inst(ptr, 42); \ | 48 return __sync_fetch_and_##inst(ptr, 42); \ |
49 } else { \ | 49 } else { \ |
50 return __sync_##inst##_and_fetch(ptr, 99); \ | 50 return __sync_##inst##_and_fetch(ptr, 99); \ |
51 } \ | 51 } \ |
52 } | 52 } |
53 | 53 |
54 FOR_ALL_RMWOP_TYPES(X) | 54 FOR_ALL_RMWOP_TYPES(X) |
55 #undef X | 55 #undef X |
56 | 56 |
57 #define X(type) \ | 57 #define X(type) \ |
58 type test_val_cmp_swap(volatile type *ptr, type oldval, type newval) { \ | 58 type test_val_cmp_swap(volatile type *ptr, type oldval, type newval) { \ |
59 return __sync_val_compare_and_swap(ptr, oldval, newval); \ | 59 return __sync_val_compare_and_swap(ptr, oldval, newval); \ |
| 60 } \ |
| 61 type test_val_cmp_swap_loop(volatile type *ptr, type oldval, type newval) { \ |
| 62 type prev; \ |
| 63 type succeeded_first_try = 1; \ |
| 64 while (1) { \ |
| 65 prev = __sync_val_compare_and_swap(ptr, oldval, newval); \ |
| 66 if (prev == oldval) \ |
| 67 break; \ |
| 68 succeeded_first_try = 0; \ |
| 69 oldval = prev; \ |
| 70 } \ |
| 71 return succeeded_first_try; \ |
60 } | 72 } |
61 | 73 |
62 ATOMIC_TYPE_TABLE | 74 ATOMIC_TYPE_TABLE |
63 #undef X | 75 #undef X |
OLD | NEW |