-
Notifications
You must be signed in to change notification settings - Fork 1.6k
atomic_flag_test, lock free type aliases #684
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
22 commits
Select commit
Hold shift + click to select a range
4fddd84
Extract simple part from #593 to have it earlier
AlexGuteniev d517d28
missing _NODISCARD
AlexGuteniev b79074f
Merge remote-tracking branch 'upstream/master' into atomic_flag_test
AlexGuteniev 3ae2c0a
Add test
AlexGuteniev d0eae56
Merge remote-tracking branch 'upstream/master' into atomic_flag_test
AlexGuteniev f2e5be5
a bit more smoke tests
AlexGuteniev a783c22
fix incorrect merge
AlexGuteniev f9f6d9d
Merge remote-tracking branch 'upstream/master' into atomic_flag_test
AlexGuteniev ec1fcad
Update tests/tr1/tests/atomic/test.cpp
AlexGuteniev 35e5ca3
Update tests/tr1/tests/atomic/test.cpp
AlexGuteniev 775eb0d
Revert "Add test"
AlexGuteniev 4d082b8
Merge branch 'atomic_flag_test' of https://github.com/AlexGuteniev/ST…
AlexGuteniev b912697
better test for atomic flags
AlexGuteniev 1a4e2be
newline
AlexGuteniev e469137
actually relaxed is wrong
AlexGuteniev 314a05d
don't capture mo
AlexGuteniev d16e111
Merge remote-tracking branch 'upstream/master' into atomic_flag_test
AlexGuteniev 53c7236
Merge remote-tracking branch 'upstream/master' into atomic_flag_test
AlexGuteniev 4306cdb
I expect it to pass
AlexGuteniev 1e79f53
Merge branch 'master' into atomic_flag_test
StephanTLavavej 66b6275
Code review feedback.
StephanTLavavej 949b259
Code review feedback, part 2.
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
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
| 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 ..\usual_latest_matrix.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,87 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
| #include <atomic> | ||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <execution> | ||
| #include <numeric> | ||
| #include <vector> | ||
|
|
||
| constexpr auto mo = std::memory_order_seq_cst; | ||
|
|
||
| template <typename FlagType, typename IsSet, typename TestAndSet, typename Clear> | ||
| void test_flags(const IsSet is_set, const TestAndSet test_and_set, const Clear clear) { | ||
| constexpr std::size_t unique = 800; | ||
| constexpr std::size_t repetitions = 800; | ||
| constexpr std::size_t total = unique * repetitions; | ||
| constexpr std::size_t dups = total - unique; | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| FlagType flags[unique]; | ||
| std::vector<FlagType*> ptrs; | ||
| ptrs.reserve(total); | ||
| for (std::size_t i = 0; i != repetitions; ++i) { | ||
| for (auto& flag : flags) { | ||
| ptrs.push_back(&flag); | ||
| } | ||
| } | ||
|
|
||
| using std::execution::par; | ||
|
|
||
| assert(std::transform_reduce(par, ptrs.begin(), ptrs.end(), 0, std::plus{}, is_set) == 0); | ||
| assert(std::transform_reduce(par, ptrs.begin(), ptrs.end(), 0, std::plus{}, test_and_set) == dups); | ||
| assert(std::transform_reduce(par, ptrs.begin(), ptrs.end(), 0, std::plus{}, is_set) == total); | ||
| assert(std::transform_reduce(par, ptrs.begin(), ptrs.end(), 0, std::plus{}, test_and_set) == total); | ||
| std::for_each(par, ptrs.begin(), ptrs.end(), clear); | ||
| assert(std::transform_reduce(par, ptrs.begin(), ptrs.end(), 0, std::plus{}, is_set) == 0); | ||
| } | ||
|
|
||
| template <typename FlagType> | ||
| void test_flags_members() { | ||
| const auto is_set = [](const FlagType* f) { return f->test(); }; | ||
| const auto test_and_set = [](FlagType* f) { return f->test_and_set(); }; | ||
| const auto clear = [](FlagType* f) { f->clear(); }; | ||
|
|
||
| test_flags<FlagType>(is_set, test_and_set, clear); | ||
| } | ||
|
|
||
| template <typename FlagType> | ||
| void test_flags_members_mo() { | ||
| const auto is_set = [](const FlagType* f) { return f->test(mo); }; | ||
| const auto test_and_set = [](FlagType* f) { return f->test_and_set(mo); }; | ||
| const auto clear = [](FlagType* f) { f->clear(mo); }; | ||
|
|
||
| test_flags<FlagType>(is_set, test_and_set, clear); | ||
| } | ||
|
|
||
| template <typename FlagType> | ||
| void test_flags_free() { | ||
| const auto is_set = [](const FlagType* f) { return std::atomic_flag_test(f); }; | ||
| const auto test_and_set = [](FlagType* f) { return std::atomic_flag_test_and_set(f); }; | ||
| const auto clear = [](FlagType* f) { std::atomic_flag_clear(f); }; | ||
|
|
||
| test_flags<FlagType>(is_set, test_and_set, clear); | ||
| } | ||
|
|
||
| template <typename FlagType> | ||
| void test_flags_free_mo() { | ||
| const auto is_set = [](const FlagType* f) { return std::atomic_flag_test_explicit(f, mo); }; | ||
| const auto test_and_set = [](FlagType* f) { return std::atomic_flag_test_and_set_explicit(f, mo); }; | ||
| const auto clear = [](FlagType* f) { std::atomic_flag_clear_explicit(f, mo); }; | ||
|
|
||
| test_flags<FlagType>(is_set, test_and_set, clear); | ||
| } | ||
|
|
||
| template <typename FlagType> | ||
| void test_flag_type() { | ||
| test_flags_members<FlagType>(); | ||
| test_flags_free<FlagType>(); | ||
| test_flags_members_mo<FlagType>(); | ||
| test_flags_free_mo<FlagType>(); | ||
| } | ||
|
|
||
| int main() { | ||
| test_flag_type<std::atomic_flag>(); | ||
| test_flag_type<volatile std::atomic_flag>(); | ||
| } | ||
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
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.