-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Make unique_lock and shared_lock use self-swap implementation of move assignment
#5337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eeccc10
LWG-4172
AlexGuteniev 60a7a54
fix clang warnings
AlexGuteniev 6971d55
Use braces to construct temporaries.
StephanTLavavej 93ea073
Include `<utility>` for `move()`.
StephanTLavavej 11b37b6
usual_matrix => impure_matrix, as /clr:pure rejects mutex
StephanTLavavej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/std/tests/LWG4172_unique_lock_self_move_assignment/env.lst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\impure_matrix.lst |
111 changes: 111 additions & 0 deletions
111
tests/std/tests/LWG4172_unique_lock_self_move_assignment/test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <cassert> | ||
| #include <mutex> | ||
| #include <shared_mutex> | ||
| #include <utility> | ||
|
|
||
| using namespace std; | ||
|
|
||
| struct lockable_with_counters { | ||
| void lock() { | ||
| ++lock_count; | ||
| } | ||
|
|
||
| void unlock() { | ||
| ++unlock_count; | ||
| } | ||
|
|
||
| void lock_shared() { | ||
| ++shared_lock_count; | ||
| } | ||
|
|
||
| void unlock_shared() { | ||
| ++shared_unlock_count; | ||
| } | ||
|
|
||
| int lock_count = 0; | ||
| int unlock_count = 0; | ||
| int shared_lock_count = 0; | ||
| int shared_unlock_count = 0; | ||
| }; | ||
|
|
||
| #ifdef __clang__ | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wself-move" | ||
| #endif // __clang__ | ||
| #pragma warning(push) | ||
| #pragma warning(disable : 26800) // use a moved-from object | ||
| int main() { | ||
| lockable_with_counters lockable1; | ||
| lockable_with_counters lockable2; | ||
|
|
||
| { | ||
| unique_lock<lockable_with_counters> lock_a(lockable1); | ||
| assert(lockable1.lock_count == 1); | ||
| assert(lockable1.unlock_count == 0); | ||
|
|
||
| lock_a = move(lock_a); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert(lockable1.lock_count == 1); | ||
| assert(lockable1.unlock_count == 0); | ||
| { | ||
| unique_lock<lockable_with_counters> lock_b(lockable2); | ||
| assert(lockable2.lock_count == 1); | ||
| assert(lockable2.unlock_count == 0); | ||
|
|
||
| lock_a = move(lock_b); | ||
|
|
||
| assert(lockable1.lock_count == 1); | ||
| assert(lockable1.unlock_count == 1); | ||
| assert(lockable2.lock_count == 1); | ||
| assert(lockable2.unlock_count == 0); | ||
| } | ||
|
|
||
| assert(lockable1.lock_count == 1); | ||
| assert(lockable1.unlock_count == 1); | ||
| assert(lockable2.lock_count == 1); | ||
| assert(lockable2.unlock_count == 0); | ||
| } | ||
|
|
||
| assert(lockable1.lock_count == 1); | ||
| assert(lockable1.unlock_count == 1); | ||
| assert(lockable2.lock_count == 1); | ||
| assert(lockable2.unlock_count == 1); | ||
|
|
||
| { | ||
| shared_lock<lockable_with_counters> lock_a(lockable1); | ||
| assert(lockable1.shared_lock_count == 1); | ||
| assert(lockable1.shared_unlock_count == 0); | ||
|
|
||
| lock_a = move(lock_a); | ||
| assert(lockable1.shared_lock_count == 1); | ||
| assert(lockable1.shared_unlock_count == 0); | ||
| { | ||
| shared_lock<lockable_with_counters> lock_b(lockable2); | ||
| assert(lockable2.shared_lock_count == 1); | ||
| assert(lockable2.shared_unlock_count == 0); | ||
|
|
||
| lock_a = move(lock_b); | ||
|
|
||
| assert(lockable1.shared_lock_count == 1); | ||
| assert(lockable1.shared_unlock_count == 1); | ||
| assert(lockable2.shared_lock_count == 1); | ||
| assert(lockable2.shared_unlock_count == 0); | ||
| } | ||
|
|
||
| assert(lockable1.shared_lock_count == 1); | ||
| assert(lockable1.shared_unlock_count == 1); | ||
| assert(lockable2.shared_lock_count == 1); | ||
| assert(lockable2.shared_unlock_count == 0); | ||
| } | ||
|
|
||
| assert(lockable1.shared_lock_count == 1); | ||
| assert(lockable1.shared_unlock_count == 1); | ||
| assert(lockable2.shared_lock_count == 1); | ||
| assert(lockable2.shared_unlock_count == 1); | ||
| } | ||
| #pragma warning(pop) | ||
| #ifdef __clang__ | ||
| #pragma clang diagnostic pop | ||
| #endif // __clang__ | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.