-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[libc++] Improve performance of std::atomic_flag on Windows #163524
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
mstorsjo
merged 8 commits into
llvm:main
from
RogerSanders:libcpp-windows-waitonaddress
Nov 13, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
63ee5da
[libc++] Improve performance of std::atomic_flag on Windows
4515628
[libc++] Fixed naming, added comments.
49efee9
[libc++] More naming and comment changes as recommended
899aed7
[libc++] Corrected loading/unloading of API set
2586c83
[libc++] Removed assumption that NULL HMODULE value is safe to use
930b0c4
[libc++] Consolidated logic into helper function
27b395d
[libc++] Switched to assume API set is already loaded as per MS STL
b6df5a5
[libc++] Fixed build error and warning
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way (e.g. a macro) to check if the function is available at compile time? we don't do this sort of check at runtime on other systems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know which OS the resulting binary will be run on, so no, no such thing, except by dropping support for windows 7 completely.
Which may be a reasonable move - ms-stl already did - but that would require a project-wide RFC, not just a mundane-looking PR to an obscure module.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #163524 (comment)
libc++ seems to have dropped Windows 7 support (for modern toolchains where _WIN32_WINNT > _WIN32_WINNT_WIN8 ), but avoiding the dependency on synchronization.lib does sound very meaningful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not true. Libc++ does support Windows 7 - but when building,
_WIN32_WINNTindicates the lowest version you require at runtime.So if your toolchain defaults to a higher version, you need to manually define
_WIN32_WINNTto the lowest version you want to support. llvm-mingw builds with_WIN32_WINNTset to Windows 7.So for things like this, like the example in chrono.cpp, we can choose to either load symbols dynamically, if targeting an older version, or link directly, if we're targeting a new enough version. But in this case, the PR author pointed out that it would require linking in another import library if we'd link directly, which both is extra work on the CMake level, and also translates to extra work for users who statically link in libc++. So as the overhead is near-zero with only loading it the first time it is called, the PR author thought it was simplest to always go with the dynamic loading approach, which sounds reasonable to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's exactly what I meant. Considering that both MinGW and Windows SDK default to _WIN32_WINNT_WIN10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if they currently aren't using the latest LLVM, I don't think that logic should be extended so that they can't update to the latest one, for things they are working on. Whether the next release is ready for shipping right now or not seems beside the point - as long as that branch is worked on, and is built for a Win7 baseline, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, considering that version 4.0 will not be released anytime soon, absolutely NO SUPPORT for it from the VideoLAN Team before its release, and that VideoLAN also provides GCC builds, I suspect that there are likely few or no end users who will be affected by LLVM's decision to drop Windows 7 support. In this case, LLVM's downstream users should perhaps reconsider their platform support policies rather than passing the burden onto LLVM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we figure out how to get synchronization.a into libc++.a? If no, we need GetProcAddress even on win11, and there is no additional support burden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can rely on llvm-lib, it's very simple, but if we have to be compatible with ar, it becomes very ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VLC 4.0 will target Windows 7 as minimal, yes.
VLC 4.0 will be LLVM-focused now, this being the default on macOS/iOS/visionOS, Android, and all Windows versions. Only some Linux versions will stay on GCC, because it is the default on some distributions.