Skip to content

Commit

Permalink
Added some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
joka921 committed Jul 12, 2024
1 parent b5b7859 commit bebe77a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/util/CopyableSynchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace ad_utility {
// a new mutex. This is sufficient for applications like in
// `getInternallyVisibleVariableColumns()` where we just want to make a
// `const` member function that modifies a `mutable` member threadsafe.
// Note that a copy-constructed `CopyableMutex` will be unlocked, even if the
// source was locked, and that copy assignment also never locks or unlocks any
// of the involved atomics.
struct CopyableMutex : std::mutex {
using std::mutex::mutex;
CopyableMutex(const CopyableMutex&) {}
Expand Down
9 changes: 6 additions & 3 deletions test/CopyableSynchronizationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ using namespace ad_utility;
TEST(CopyableSynchronization, CopyableMutex) {
// Not much to test here.
CopyableMutex m1;
[[maybe_unused]] CopyableMutex m2{m1};
m1 = m2;
m1.lock();
[[maybe_unused]] CopyableMutex m2{m1};
// m2 is still unlocked.
EXPECT_TRUE(m2.try_lock());
m1.unlock();
m2.unlock();
m1 = m2;
// m1 is still locked;
EXPECT_FALSE(m1.try_lock());
m1.unlock();
}

// _________________________________________________
Expand Down

0 comments on commit bebe77a

Please sign in to comment.