diff options
Diffstat (limited to 'test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons')
11 files changed, 542 insertions, 0 deletions
diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp new file mode 100644 index 0000000000000..446807f3f3335 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <shared_mutex> + +// template <class Mutex> class shared_lock; + +// shared_lock& operator=(shared_lock const&) = delete; + +#include <shared_mutex> + +#if _LIBCPP_STD_VER > 11 + +std::shared_timed_mutex m0; +std::shared_timed_mutex m1; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_lock<std::shared_timed_mutex> lk0(m0); + std::shared_lock<std::shared_timed_mutex> lk1(m1); + lk1 = lk0; +#else +# error +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp new file mode 100644 index 0000000000000..370c1fa4e3361 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <shared_mutex> + +// template <class Mutex> class shared_lock; + +// shared_lock(shared_lock const&) = delete; + +#include <shared_mutex> + +#if _LIBCPP_STD_VER > 11 +std::shared_timed_mutex m; +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_lock<std::shared_timed_mutex> lk0(m); + std::shared_lock<std::shared_timed_mutex> lk = lk0; +#else +# error +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp new file mode 100644 index 0000000000000..2c1c665fdedae --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// shared_lock(); + +#include <shared_mutex> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_lock<std::shared_timed_mutex> ul; + assert(!ul.owns_lock()); + assert(ul.mutex() == nullptr); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp new file mode 100644 index 0000000000000..8676f2ca0472a --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// shared_lock& operator=(shared_lock&& u); + +#include <shared_mutex> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +std::shared_timed_mutex m0; +std::shared_timed_mutex m1; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_lock<std::shared_timed_mutex> lk0(m0); + std::shared_lock<std::shared_timed_mutex> lk1(m1); + lk1 = std::move(lk0); + assert(lk1.mutex() == &m0); + assert(lk1.owns_lock() == true); + assert(lk0.mutex() == nullptr); + assert(lk0.owns_lock() == false); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp new file mode 100644 index 0000000000000..f59d2e826980d --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// shared_lock(shared_lock&& u); + +#include <shared_mutex> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 +std::shared_timed_mutex m; +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_lock<std::shared_timed_mutex> lk0(m); + std::shared_lock<std::shared_timed_mutex> lk = std::move(lk0); + assert(lk.mutex() == &m); + assert(lk.owns_lock() == true); + assert(lk0.mutex() == nullptr); + assert(lk0.owns_lock() == false); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp new file mode 100644 index 0000000000000..c8a0287314bfd --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// explicit shared_lock(mutex_type& m); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +std::shared_timed_mutex m; + +typedef std::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef std::chrono::milliseconds ms; +typedef std::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + time_point t1; + { + std::shared_lock<std::shared_timed_mutex> ul(m); + t1 = Clock::now(); + } + ns d = t1 - t0 - ms(250); + assert(d < ms(50)); // within 50ms +} + +void g() +{ + time_point t0 = Clock::now(); + time_point t1; + { + std::shared_lock<std::shared_timed_mutex> ul(m); + t1 = Clock::now(); + } + ns d = t1 - t0; + assert(d < ms(50)); // within 50ms +} + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + m.lock(); + std::vector<std::thread> v; + for (int i = 0; i < 5; ++i) + v.push_back(std::thread(f)); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + for (auto& t : v) + t.join(); + m.lock_shared(); + for (auto& t : v) + t = std::thread(g); + std::thread q(f); + std::this_thread::sleep_for(ms(250)); + m.unlock_shared(); + for (auto& t : v) + t.join(); + q.join(); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp new file mode 100644 index 0000000000000..3b49b30290521 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// shared_lock(mutex_type& m, adopt_lock_t); + +#include <shared_mutex> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_timed_mutex m; + m.lock_shared(); + std::shared_lock<std::shared_timed_mutex> lk(m, std::adopt_lock); + assert(lk.mutex() == &m); + assert(lk.owns_lock() == true); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp new file mode 100644 index 0000000000000..bbc38fcadb109 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// shared_lock(mutex_type& m, defer_lock_t); + +#include <shared_mutex> +#include <cassert> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_timed_mutex m; + std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock); + assert(lk.mutex() == &m); + assert(lk.owns_lock() == false); +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp new file mode 100644 index 0000000000000..9816e57f692a2 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class timed_mutex; + +// template <class Rep, class Period> +// shared_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +std::shared_timed_mutex m; + +typedef std::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef std::chrono::milliseconds ms; +typedef std::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + std::shared_lock<std::shared_timed_mutex> lk(m, ms(300)); + assert(lk.owns_lock() == true); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + assert(d < ms(50)); // within 50ms +} + +void f2() +{ + time_point t0 = Clock::now(); + std::shared_lock<std::shared_timed_mutex> lk(m, ms(250)); + assert(lk.owns_lock() == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + assert(d < ms(50)); // within 50ms +} + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + m.lock(); + std::vector<std::thread> v; + for (int i = 0; i < 5; ++i) + v.push_back(std::thread(f1)); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + for (auto& t : v) + t.join(); + } + { + m.lock(); + std::vector<std::thread> v; + for (int i = 0; i < 5; ++i) + v.push_back(std::thread(f2)); + std::this_thread::sleep_for(ms(300)); + m.unlock(); + for (auto& t : v) + t.join(); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp new file mode 100644 index 0000000000000..5d188ab06737c --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// 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> + +// class shared_timed_mutex; + +// template <class Clock, class Duration> +// shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +std::shared_timed_mutex m; + +typedef std::chrono::steady_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef std::chrono::milliseconds ms; +typedef std::chrono::nanoseconds ns; + +void f1() +{ + time_point t0 = Clock::now(); + std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + ms(300)); + assert(lk.owns_lock() == true); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + assert(d < ns(50000000)); // within 50ms +} + +void f2() +{ + time_point t0 = Clock::now(); + std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + ms(250)); + assert(lk.owns_lock() == false); + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + assert(d < ms(50)); // within 50ms +} + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + m.lock(); + std::vector<std::thread> v; + for (int i = 0; i < 5; ++i) + v.push_back(std::thread(f1)); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + for (auto& t : v) + t.join(); + } + { + m.lock(); + std::vector<std::thread> v; + for (int i = 0; i < 5; ++i) + v.push_back(std::thread(f2)); + std::this_thread::sleep_for(ms(300)); + m.unlock(); + for (auto& t : v) + t.join(); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp new file mode 100644 index 0000000000000..f2d4e0deb73f3 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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; + +// shared_lock(mutex_type& m, try_to_lock_t); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +#if _LIBCPP_STD_VER > 11 + +std::shared_timed_mutex m; + +typedef std::chrono::system_clock Clock; +typedef Clock::time_point time_point; +typedef Clock::duration duration; +typedef std::chrono::milliseconds ms; +typedef std::chrono::nanoseconds ns; + +void f() +{ + time_point t0 = Clock::now(); + { + std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock); + assert(lk.owns_lock() == false); + } + { + std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock); + assert(lk.owns_lock() == false); + } + { + std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock); + assert(lk.owns_lock() == false); + } + while (true) + { + std::shared_lock<std::shared_timed_mutex> lk(m, std::try_to_lock); + if (lk.owns_lock()) + break; + } + time_point t1 = Clock::now(); + ns d = t1 - t0 - ms(250); + assert(d < ms(200)); // within 200ms +} + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + m.lock(); + std::vector<std::thread> v; + for (int i = 0; i < 5; ++i) + v.push_back(std::thread(f)); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + for (auto& t : v) + t.join(); +#endif // _LIBCPP_STD_VER > 11 +} |