[flang][runtime] Make defined formatted I/O process format elementally (#74150)
[llvm-project.git] / libcxx / test / support / cmpxchg_loop.h
blobe3416060981317e0da9a40bbdb45d9577f1f6c39
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <atomic>
11 template <class A>
12 bool cmpxchg_weak_loop(A& atomic, typename A::value_type& expected, typename A::value_type desired) {
13 for (int i = 0; i < 10; i++) {
14 if (atomic.compare_exchange_weak(expected, desired) == true) {
15 return true;
19 return false;
22 template <class A>
23 bool cmpxchg_weak_loop(A& atomic, typename A::value_type& expected, typename A::value_type desired,
24 std::memory_order success,
25 std::memory_order failure) {
26 for (int i = 0; i < 10; i++) {
27 if (atomic.compare_exchange_weak(expected, desired, success,
28 failure) == true) {
29 return true;
33 return false;
36 template <class A>
37 bool c_cmpxchg_weak_loop(A* atomic, typename A::value_type* expected, typename A::value_type desired) {
38 for (int i = 0; i < 10; i++) {
39 if (std::atomic_compare_exchange_weak(atomic, expected, desired) == true) {
40 return true;
44 return false;
47 template <class A>
48 bool c_cmpxchg_weak_loop(A* atomic, typename A::value_type* expected, typename A::value_type desired,
49 std::memory_order success,
50 std::memory_order failure) {
51 for (int i = 0; i < 10; i++) {
52 if (std::atomic_compare_exchange_weak_explicit(atomic, expected, desired,
53 success, failure) == true) {
54 return true;
58 return false;