[libcxx-commits] [libcxx] [libc++] Improve performance of std::atomic_flag on Windows (PR #163524)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 4 03:57:19 PST 2025


================
@@ -101,6 +105,46 @@ static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const vo
   _umtx_op(const_cast<__cxx_atomic_contention_t*>(__ptr), UMTX_OP_WAKE, __notify_one ? 1 : INT_MAX, nullptr, nullptr);
 }
 
+#elif defined(_WIN32)
+
+static void
+__libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) {
+  // WaitOnAddress was added in Windows 8 (build 9200)
+  static auto wait_on_address = reinterpret_cast<BOOL(WINAPI*)(volatile void*, PVOID, SIZE_T, DWORD)>(
+      GetProcAddress(GetModuleHandleW(L"api-ms-win-core-synch-l1-2-0.dll"), "WaitOnAddress"));
+  if (wait_on_address != nullptr) {
----------------
mstorsjo wrote:

Thanks, this seems reasonably straightforward again.

Regarding "supports and not supports at the same time" - this is pretty much the same as how it works on macOS; if you do a default build of things, it sets the minimum deployment target to the latest/current version, but if you want to you can build with `-mmacosx-version-min=<old>` to target older things. If targeting an older version, potentially unavailable symbols are linked to weakly and one can make conditionals to check whether they exist before calling them.

And regarding bumping the minimum supported version on Windows; we have VLC as one fairly major user, who still are targeting Windows 7 in their latest version.

https://github.com/llvm/llvm-project/pull/163524


More information about the libcxx-commits mailing list