[libcxx-commits] [libcxx] [libc++] Always use uintptr_t as the state type of once_flag (PR #220603)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 2 07:19:48 PDT 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/220603
None
>From a51d1fcc898b707226a786d379b18ef542e9d7f2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 2 Sep 2026 16:19:12 +0200
Subject: [PATCH] [libc++] Always use uintptr_t as the state type of once_flag
---
libcxx/include/__mutex/once_flag.h | 16 +++++-----------
libcxx/src/call_once.cpp | 2 +-
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/libcxx/include/__mutex/once_flag.h b/libcxx/include/__mutex/once_flag.h
index 63c97a2921412..c1051d4806800 100644
--- a/libcxx/include/__mutex/once_flag.h
+++ b/libcxx/include/__mutex/once_flag.h
@@ -52,18 +52,12 @@ struct once_flag {
once_flag(const once_flag&) = delete;
once_flag& operator=(const once_flag&) = delete;
-#ifdef _WIN32
- typedef uintptr_t _State_type;
-#else
- typedef unsigned long _State_type;
-#endif
-
- static const _State_type _Unset = 0;
- static const _State_type _Pending = 1;
- static const _State_type _Complete = ~_State_type(0);
+ static const uintptr_t _Unset = 0;
+ static const uintptr_t _Pending = 1;
+ static const uintptr_t _Complete = ~uintptr_t(0);
private:
- _State_type __state_;
+ uintptr_t __state_;
#ifndef _LIBCPP_CXX03_LANG
template <class _Callable, class... _Args>
@@ -114,7 +108,7 @@ void _LIBCPP_HIDE_FROM_ABI __call_once_proxy(void* __vp) {
}
_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
-_LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile once_flag::_State_type&, void*, void (*)(void*));
+_LIBCPP_EXPORTED_FROM_ABI void __call_once(volatile uintptr_t&, void*, void (*)(void*));
_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
template <class _ValueType>
diff --git a/libcxx/src/call_once.cpp b/libcxx/src/call_once.cpp
index 015b874cffa44..3f410871669d6 100644
--- a/libcxx/src/call_once.cpp
+++ b/libcxx/src/call_once.cpp
@@ -30,7 +30,7 @@ static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
#endif
-void __call_once(volatile once_flag::_State_type& flag, void* arg, void (*func)(void*)) {
+void __call_once(volatile uintptr_t& flag, void* arg, void (*func)(void*)) {
#if !_LIBCPP_HAS_THREADS
if (flag == once_flag::_Unset) {
More information about the libcxx-commits
mailing list