diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp index 6025b0c3b465bd..a95c2ef0029de1 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp @@ -18,27 +18,29 @@ // -> lock_guard<_Mutex>; // C++17 #include -#include #include - -#include "make_test_thread.h" #include "test_macros.h" -std::mutex m; +struct TestMutex { + bool locked = false; + TestMutex() = default; + ~TestMutex() { assert(!locked); } -void do_try_lock() { - assert(m.try_lock() == false); -} + void lock() { assert(!locked); locked = true; } + bool try_lock() { if (locked) return false; locked = true; return true; } + void unlock() { assert(locked); locked = false; } + + TestMutex(TestMutex const&) = delete; + TestMutex& operator=(TestMutex const&) = delete; +}; int main(int, char**) { + TestMutex m; { - std::lock_guard lg(m); - std::thread t = support::make_test_thread(do_try_lock); - t.join(); + std::lock_guard lg(m); + assert(m.locked); } - - m.lock(); - m.unlock(); + assert(!m.locked); #if TEST_STD_VER >= 17 std::lock_guard lg(m); diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp index ece330134f2cda..863948763e2ef7 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: no-threads // UNSUPPORTED: c++03, c++11 // @@ -79,10 +78,12 @@ void test() { } int main(int, char**) { +#ifndef TEST_HAS_NO_THREADS #if TEST_STD_VER >= 17 test(); #endif test(); +#endif test(); // Use shared_lock with a dummy mutex class that tracks whether each diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp index d36ca1d38f8f13..9097ac74d1272b 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: no-threads // UNSUPPORTED: c++03, c++11 // @@ -99,10 +98,12 @@ void test() { } int main(int, char**) { +#ifndef TEST_HAS_NO_THREADS #if TEST_STD_VER >= 17 test(); #endif test(); +#endif test(); // Use shared_lock with a dummy mutex class that tracks whether each diff --git a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp index b6146680b6e353..ccab79d4db0160 100644 --- a/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp +++ b/libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: no-threads // UNSUPPORTED: c++03, c++11 // @@ -104,10 +103,12 @@ void test() { } int main(int, char**) { +#ifndef TEST_HAS_NO_THREADS #if TEST_STD_VER >= 17 test(); #endif test(); +#endif test(); // Use shared_lock with a dummy mutex class that tracks whether each