[atomics.flag] completed. Initialization is not working on clang and can't be made to work without defaulted default constructors.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@115207 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2010-09-30 21:05:29 +00:00
parent f701e25c49
commit 79101aec3a
12 changed files with 515 additions and 4 deletions

View File

@ -2556,7 +2556,7 @@ typedef struct _LIBCPP_VISIBLE atomic_flag
atomic_flag() = default;
#else
_LIBCPP_INLINE_VISIBILITY
atomic_flag() : __flg_(false) {};
atomic_flag() {};
#endif
#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// void atomic_flag_clear(volatile atomic_flag*);
// void atomic_flag_clear(atomic_flag*);
#include <atomic>
#include <cassert>
int main()
{
{
std::atomic_flag f;
f.test_and_set();
atomic_flag_clear(&f);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
atomic_flag_clear(&f);
assert(f.test_and_set() == 0);
}
}

View File

@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// void atomic_flag_clear_explicit(volatile atomic_flag*, memory_order);
// void atomic_flag_clear_explicit(atomic_flag*, memory_order);
#include <atomic>
#include <cassert>
int main()
{
{
std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_consume);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_consume);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
atomic_flag_clear_explicit(&f, std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
}

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// bool atomic_flag_test_and_set(volatile atomic_flag*);
// bool atomic_flag_test_and_set(atomic_flag*);
#include <atomic>
#include <cassert>
int main()
{
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set(&f) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set(&f) == 0);
assert(f.test_and_set() == 1);
}
}

View File

@ -0,0 +1,94 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// bool atomic_flag_test_and_set_explicit(volatile atomic_flag*, memory_order);
// bool atomic_flag_test_and_set_explicit(atomic_flag*, memory_order);
#include <atomic>
#include <cassert>
int main()
{
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_relaxed) == 0);
assert(f.test_and_set() == 1);
}
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_consume) == 0);
assert(f.test_and_set() == 1);
}
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_acquire) == 0);
assert(f.test_and_set() == 1);
}
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_release) == 0);
assert(f.test_and_set() == 1);
}
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_acq_rel) == 0);
assert(f.test_and_set() == 1);
}
{
std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_seq_cst) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_relaxed) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_consume) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_acquire) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_release) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_acq_rel) == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(atomic_flag_test_and_set_explicit(&f, std::memory_order_seq_cst) == 0);
assert(f.test_and_set() == 1);
}
}

View File

@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// void clear(memory_order = memory_order_seq_cst);
// void clear(memory_order = memory_order_seq_cst) volatile;
#include <atomic>
#include <cassert>
int main()
{
{
std::atomic_flag f;
f.test_and_set();
f.clear();
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_consume);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
f.clear();
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_relaxed);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_consume);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_release);
assert(f.test_and_set() == 0);
}
{
volatile std::atomic_flag f;
f.test_and_set();
f.clear(std::memory_order_seq_cst);
assert(f.test_and_set() == 0);
}
}

View File

@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// atomic_flag& operator=(const atomic_flag&) = delete;
#include <atomic>
#include <cassert>
int main()
{
std::atomic_flag f0;
std::atomic_flag f;
f = f0;
}

View File

@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// atomic_flag(const atomic_flag&) = delete;
#include <atomic>
#include <cassert>
int main()
{
std::atomic_flag f0;
std::atomic_flag f(f0);
}

View File

@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// atomic_flag& operator=(const atomic_flag&) = delete;
#include <atomic>
#include <cassert>
int main()
{
std::atomic_flag f0;
volatile std::atomic_flag f;
f = f0;
}

View File

@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// atomic_flag() = default;
#include <atomic>
#include <cassert>
int main()
{
std::atomic_flag f;
}

View File

@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <atomic>
// struct atomic_flag
// atomic_flag() = ATOMIC_FLAG_INIT;
#include <atomic>
#include <cassert>
int main()
{
std::atomic_flag f = ATOMIC_FLAG_INIT;
assert(f.test_and_set() == 0);
}

View File

@ -19,7 +19,88 @@
int main()
{
std::atomic_flag f;
assert(f.test_and_set() == 0);
assert(f.test_and_set() == 1);
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set() == 0);
assert(f.test_and_set() == 1);
}
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_relaxed) == 0);
assert(f.test_and_set(std::memory_order_relaxed) == 1);
}
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_consume) == 0);
assert(f.test_and_set(std::memory_order_consume) == 1);
}
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_acquire) == 0);
assert(f.test_and_set(std::memory_order_acquire) == 1);
}
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_release) == 0);
assert(f.test_and_set(std::memory_order_release) == 1);
}
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_acq_rel) == 0);
assert(f.test_and_set(std::memory_order_acq_rel) == 1);
}
{
std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_seq_cst) == 0);
assert(f.test_and_set(std::memory_order_seq_cst) == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set() == 0);
assert(f.test_and_set() == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_relaxed) == 0);
assert(f.test_and_set(std::memory_order_relaxed) == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_consume) == 0);
assert(f.test_and_set(std::memory_order_consume) == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_acquire) == 0);
assert(f.test_and_set(std::memory_order_acquire) == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_release) == 0);
assert(f.test_and_set(std::memory_order_release) == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_acq_rel) == 0);
assert(f.test_and_set(std::memory_order_acq_rel) == 1);
}
{
volatile std::atomic_flag f;
f.clear();
assert(f.test_and_set(std::memory_order_seq_cst) == 0);
assert(f.test_and_set(std::memory_order_seq_cst) == 1);
}
}