MSVC: Use C11 atomics if supported via /experimental:c11atomics#1427
Open
sethk wants to merge 3 commits intoNetflix:masterfrom
Open
MSVC: Use C11 atomics if supported via /experimental:c11atomics#1427sethk wants to merge 3 commits intoNetflix:masterfrom
sethk wants to merge 3 commits intoNetflix:masterfrom
Conversation
MSVC has added support for <stdatomic.h>, but it requires passing /experimental:c11atomics to enable it. Without this flag, the backwards compatibility header libvmaf/src/compat/msvc/stdatomic.h is used MSVC has been shipping stdatomic.h since they added /experimental:c11atomics, but without this flag on for example MSVC 14.42.34433, <stdatomic.h> will be found and #included, but won't work due to /std:c11 being used without /experimental:c11atomics. This should be backwards compatible with older MSVC that doesn't support c11atomics, because the test for stdatomic.h will fail and the compat. header will be used as before.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Recent MSVC supports the C11 atomics standard if given /experimental:c11atomics.
The compatibility header libvmaf/src/compat/msvc/stdatomic.h does not work on versions of MSVC which support c11atomics. Even without the /experimental:c11atomics flag, the MSVC version of stdatomic.h is included, but the _Atomic() declaration specifier is not active, so it fails to compile.
The Meson tests here check whether a trivial program that #includes stdatomic.h compiles via cc.check_header(). If that fails, and we're using MSVC, it tries again with /experimental:c11atomics added. The compat headers are only used if stdatomic.h does not exist on the system at all.
-DHAVE_STDATOMIC_H is used to ensure that everywhere stdatomic.h is used, stdatomic_dependency is also added to the Meson target. There were several places where this was missing, meaning that those targets were likely broken for compilers without c11 atomics.
For versions of MSVC before c11atomics support was added, I attempted to fix the compat header, but I don't have a good way to test this. The compat header has been broken for a while because it depends on another internal header, "common/attributes.h", which no longer exists in the project.