//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef ATOMIC_HELPERS_H #define ATOMIC_HELPERS_H #include #include "test_macros.h" struct UserAtomicType { int i; explicit UserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} friend bool operator==(const UserAtomicType& x, const UserAtomicType& y) { return x.i == y.i; } }; /* Enable these once we have P0528 struct WeirdUserAtomicType { char i, j, k; // the 3 chars of doom explicit WeirdUserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} friend bool operator==(const WeirdUserAtomicType& x, const WeirdUserAtomicType& y) { return x.i == y.i; } }; struct PaddedUserAtomicType { char i; int j; // probably lock-free? explicit PaddedUserAtomicType(int d = 0) TEST_NOEXCEPT : i(d) {} friend bool operator==(const PaddedUserAtomicType& x, const PaddedUserAtomicType& y) { return x.i == y.i; } }; */ struct LargeUserAtomicType { int a[128]; /* decidedly not lock-free */ LargeUserAtomicType(int d = 0) TEST_NOEXCEPT { for (auto&& e : a) e = d++; } friend bool operator==(LargeUserAtomicType const& x, LargeUserAtomicType const& y) TEST_NOEXCEPT { for (int i = 0; i < 128; ++i) if (x.a[i] != y.a[i]) return false; return true; } }; template