brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · feed0fb Raw
63 lines · cpp
1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7 8// UNSUPPORTED: c++03, c++11, c++14, c++179// XFAIL: !has-64-bit-atomics10// XFAIL: !has-1024-bit-atomics11 12// T load(memory_order = memory_order::seq_cst) const noexcept;13 14#include <atomic>15#include <concepts>16#include <cassert>17#include <type_traits>18 19#include "atomic_helpers.h"20#include "test_helper.h"21#include "test_macros.h"22 23template <typename T>24struct TestLoad {25  void operator()() const {26    T x(T(1));27    std::atomic_ref<T> const a(x);28 29    {30      std::same_as<T> decltype(auto) y = a.load();31      assert(y == T(1));32      ASSERT_NOEXCEPT(a.load());33    }34 35    {36      std::same_as<T> decltype(auto) y = a.load(std::memory_order_seq_cst);37      assert(y == T(1));38      ASSERT_NOEXCEPT(a.load(std::memory_order_seq_cst));39    }40 41    // memory_order::seq_cst42    {43      auto store           = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val); };44      auto load_no_arg     = [](std::atomic_ref<T> const& y) { return y.load(); };45      auto load_with_order = [](std::atomic_ref<T> const& y) { return y.load(std::memory_order::seq_cst); };46      test_seq_cst<T>(store, load_no_arg);47      test_seq_cst<T>(store, load_with_order);48    }49 50    // memory_order::release51    {52      auto store = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val, std::memory_order::release); };53      auto load  = [](std::atomic_ref<T> const& y) { return y.load(std::memory_order::acquire); };54      test_acquire_release<T>(store, load);55    }56  }57};58 59int main(int, char**) {60  TestEachAtomicType<TestLoad>()();61  return 0;62}63