Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions libcxx/include/__mutex/unique_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ class unique_lock {
}

_LIBCPP_HIDE_FROM_ABI unique_lock& operator=(unique_lock&& __u) _NOEXCEPT {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically for this LWG issue you need to update the synopsis due to the adding of noexcept, but that seems already done.

if (__owns_)
__m_->unlock();

__m_ = __u.__m_;
__owns_ = __u.__owns_;
__u.__m_ = nullptr;
__u.__owns_ = false;
unique_lock{std::move(__u)}.swap(*this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should include <__utility/move.h> in <__mutex/unique_lock.h> and <shared_mutex>. And then you need to add

_LIBCPP_PUSH_MACROS
#include <__undef_macros>

immediately before

_LIBCPP_BEGIN_NAMESPACE_STD

, and

_LIBCPP_POP_MACROS

immediately after

_LIBCPP_END_NAMESPACE_STD

return *this;
}

Expand Down
9 changes: 1 addition & 8 deletions libcxx/include/shared_mutex
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,7 @@ public:
}

_LIBCPP_HIDE_FROM_ABI shared_lock& operator=(shared_lock&& __u) _NOEXCEPT {
if (__owns_)
__m_->unlock_shared();
__m_ = nullptr;
__owns_ = false;
__m_ = __u.__m_;
__owns_ = __u.__owns_;
__u.__m_ = nullptr;
__u.__owns_ = false;
shared_lock{std::move(__u)}.swap(*this);
return *this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,31 @@

#include "test_macros.h"


int main(int, char**)
{
{
int main(int, char**) {
{
typedef std::shared_timed_mutex M;
M m0;
M m1;
std::shared_lock<M> lk0(m0);
std::shared_lock<M> lk1(m1);

// Test self move assignment for lk0.
lk0 = std::move(lk0);
assert(lk0.mutex() == std::addressof(m0));
assert(lk0.owns_lock() == true);

lk1 = std::move(lk0);
assert(lk1.mutex() == std::addressof(m0));
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
}
{

// Test self move assignment for lk1.
lk1 = std::move(lk1);
assert(lk1.mutex() == std::addressof(m0));
assert(lk1.owns_lock() == true);
}
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this test does not validate the noexcept status of the function, can you add that.
(The next test should add it since there it's a new requirement.)
The test for swap has an example how to test for noexcept.

typedef nasty_mutex M;
M m0;
M m1;
Expand All @@ -47,7 +56,7 @@ int main(int, char**)
assert(lk1.owns_lock() == true);
assert(lk0.mutex() == nullptr);
assert(lk0.owns_lock() == false);
}
}

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ int main(int, char**) {
std::unique_lock<checking_mutex> lk0(m0);
std::unique_lock<checking_mutex> lk1(m1);

// Test self move assignment for lk0.
lk0 = std::move(lk0);
assert(lk0.mutex() == std::addressof(m0));
assert(lk0.owns_lock() == true);

auto& result = (lk1 = std::move(lk0));

assert(&result == &lk1);
assert(lk1.mutex() == std::addressof(m0));
assert(lk1.owns_lock());
assert(lk0.mutex() == nullptr);
assert(!lk0.owns_lock());
assert(lk0.owns_lock() == false);

// Test self move assignment for lk1
lk1 = std::move(lk1);
assert(lk1.mutex() == std::addressof(m0));
assert(lk1.owns_lock() == true);
return 0;
}
Loading