aboutsummaryrefslogtreecommitdiff
path: root/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-09-06 18:46:46 +0000
commit61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch)
treeec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod
parentf857581820d15e410e9945d2fcd5f7163be25a96 (diff)
Notes
Diffstat (limited to 'test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod')
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp45
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp46
-rw-r--r--test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp53
3 files changed, 144 insertions, 0 deletions
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp
new file mode 100644
index 0000000000000..8505763e44bc0
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// void swap(shared_lock& u) noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+struct mutex
+{
+ void lock_shared() {}
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk1(m);
+ std::shared_lock<mutex> lk2;
+ lk1.swap(lk2);
+ assert(lk1.mutex() == nullptr);
+ assert(lk1.owns_lock() == false);
+ assert(lk2.mutex() == &m);
+ assert(lk2.owns_lock() == true);
+ static_assert(noexcept(lk1.swap(lk2)), "member swap must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp
new file mode 100644
index 0000000000000..057dbc4cd3b7a
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// template <class Mutex>
+// void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+struct mutex
+{
+ void lock_shared() {}
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk1(m);
+ std::shared_lock<mutex> lk2;
+ swap(lk1, lk2);
+ assert(lk1.mutex() == nullptr);
+ assert(lk1.owns_lock() == false);
+ assert(lk2.mutex() == &m);
+ assert(lk2.owns_lock() == true);
+ static_assert(noexcept(swap(lk1, lk2)), "non-member swap must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp
new file mode 100644
index 0000000000000..65ddca6247258
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: libcpp-has-no-threads
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// mutex_type* release() noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+struct mutex
+{
+ static int lock_count;
+ static int unlock_count;
+ void lock_shared() {++lock_count;}
+ void unlock_shared() {++unlock_count;}
+};
+
+int mutex::lock_count = 0;
+int mutex::unlock_count = 0;
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk(m);
+ assert(lk.mutex() == &m);
+ assert(lk.owns_lock() == true);
+ assert(mutex::lock_count == 1);
+ assert(mutex::unlock_count == 0);
+ assert(lk.release() == &m);
+ assert(lk.mutex() == nullptr);
+ assert(lk.owns_lock() == false);
+ assert(mutex::lock_count == 1);
+ assert(mutex::unlock_count == 0);
+ static_assert(noexcept(lk.release()), "release must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}