brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · ea01a3d Raw
62 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// void store(T, memory_order = memory_order::seq_cst) const noexcept;13 14#include <atomic>15#include <cassert>16#include <type_traits>17 18#include "atomic_helpers.h"19#include "test_helper.h"20#include "test_macros.h"21 22template <typename T>23struct TestStore {24  void operator()() const {25    T x(T(1));26    std::atomic_ref<T> const a(x);27 28    a.store(T(2));29    assert(x == T(2));30    ASSERT_NOEXCEPT(a.store(T(1)));31 32    a.store(T(3), std::memory_order_seq_cst);33    assert(x == T(3));34    ASSERT_NOEXCEPT(a.store(T(0), std::memory_order_seq_cst));35 36    // TODO memory_order::relaxed37 38    // memory_order::seq_cst39    {40      auto store_no_arg     = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val); };41      auto store_with_order = [](std::atomic_ref<T> const& y, T, T new_val) {42        y.store(new_val, std::memory_order::seq_cst);43      };44      auto load = [](std::atomic_ref<T> const& y) { return y.load(); };45      test_seq_cst<T>(store_no_arg, load);46      test_seq_cst<T>(store_with_order, load);47    }48 49    // memory_order::release50    {51      auto store = [](std::atomic_ref<T> const& y, T, T new_val) { y.store(new_val, std::memory_order::release); };52      auto load  = [](std::atomic_ref<T> const& y) { return y.load(std::memory_order::acquire); };53      test_acquire_release<T>(store, load);54    }55  }56};57 58int main(int, char**) {59  TestEachAtomicType<TestStore>()();60  return 0;61}62