Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petrhosek committed Jul 13, 2024
1 parent 2b4d430 commit e06a8e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@
// -> lock_guard<_Mutex>; // C++17

#include <mutex>
#include <cstdlib>
#include <cassert>

#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<std::mutex> lg(m);
std::thread t = support::make_test_thread(do_try_lock);
t.join();
std::lock_guard<TestMutex> lg(m);
assert(m.locked);
}

m.lock();
m.unlock();
assert(!m.locked);

#if TEST_STD_VER >= 17
std::lock_guard lg(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-threads
// UNSUPPORTED: c++03, c++11

// <shared_mutex>
Expand Down Expand Up @@ -79,10 +78,12 @@ void test() {
}

int main(int, char**) {
#ifndef TEST_HAS_NO_THREADS
#if TEST_STD_VER >= 17
test<std::shared_mutex>();
#endif
test<std::shared_timed_mutex>();
#endif
test<TrackedMutex>();

// Use shared_lock with a dummy mutex class that tracks whether each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-threads
// UNSUPPORTED: c++03, c++11

// <shared_mutex>
Expand Down Expand Up @@ -99,10 +98,12 @@ void test() {
}

int main(int, char**) {
#ifndef TEST_HAS_NO_THREADS
#if TEST_STD_VER >= 17
test<std::shared_mutex>();
#endif
test<std::shared_timed_mutex>();
#endif
test<TrackedMutex>();

// Use shared_lock with a dummy mutex class that tracks whether each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-threads
// UNSUPPORTED: c++03, c++11

// <shared_mutex>
Expand Down Expand Up @@ -104,10 +103,12 @@ void test() {
}

int main(int, char**) {
#ifndef TEST_HAS_NO_THREADS
#if TEST_STD_VER >= 17
test<std::shared_mutex>();
#endif
test<std::shared_timed_mutex>();
#endif
test<TrackedMutex>();

// Use shared_lock with a dummy mutex class that tracks whether each
Expand Down

0 comments on commit e06a8e6

Please sign in to comment.