MSVC: Use C11 atomics if supported via /experimental:c11atomics #1427
+63
−25
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.