68 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <atomic>10 11// struct atomic_flag12 13// void atomic_flag_clear_explicit(volatile atomic_flag*, memory_order);14// void atomic_flag_clear_explicit(atomic_flag*, memory_order);15 16#include <atomic>17#include <cassert>18 19#include "test_macros.h"20 21int main(int, char**)22{23 {24 std::atomic_flag f; // uninitialized first25 std::atomic_flag_clear_explicit(&f, std::memory_order_relaxed);26 assert(f.test_and_set() == 0);27 std::atomic_flag_clear_explicit(&f, std::memory_order_relaxed);28 assert(f.test_and_set() == 0);29 }30 {31 std::atomic_flag f;32 std::atomic_flag_clear_explicit(&f, std::memory_order_release);33 assert(f.test_and_set() == 0);34 std::atomic_flag_clear_explicit(&f, std::memory_order_release);35 assert(f.test_and_set() == 0);36 }37 {38 std::atomic_flag f;39 std::atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);40 assert(f.test_and_set() == 0);41 std::atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);42 assert(f.test_and_set() == 0);43 }44 {45 volatile std::atomic_flag f;46 std::atomic_flag_clear_explicit(&f, std::memory_order_relaxed);47 assert(f.test_and_set() == 0);48 std::atomic_flag_clear_explicit(&f, std::memory_order_relaxed);49 assert(f.test_and_set() == 0);50 }51 {52 volatile std::atomic_flag f;53 std::atomic_flag_clear_explicit(&f, std::memory_order_release);54 assert(f.test_and_set() == 0);55 std::atomic_flag_clear_explicit(&f, std::memory_order_release);56 assert(f.test_and_set() == 0);57 }58 {59 volatile std::atomic_flag f;60 std::atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);61 assert(f.test_and_set() == 0);62 std::atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);63 assert(f.test_and_set() == 0);64 }65 66 return 0;67}68