[libcxx-commits] [libcxx] [libc++] Move threading and random device config into <__configuration/platform.h> (PR #206262)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 27 09:29:11 PDT 2026
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/206262
>From 56a61b365c3f8f023cfc65c923a8571b91a70319 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 27 Jun 2026 18:20:29 +0200
Subject: [PATCH] [libc++] Move threading and random device config into
<__configuration/platform.h>
---
libcxx/include/__config | 145 ----------------------
libcxx/include/__configuration/platform.h | 144 +++++++++++++++++++++
2 files changed, 144 insertions(+), 145 deletions(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 3f271ff504767..edafe59278821 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -62,50 +62,6 @@
# define _LIBCPP_SHORT_WCHAR 1
# endif
-// Libc++ supports various implementations of std::random_device.
-//
-// _LIBCPP_USING_DEV_RANDOM
-// Read entropy from the given file, by default `/dev/urandom`.
-// If a token is provided, it is assumed to be the path to a file
-// to read entropy from. This is the default behavior if nothing
-// else is specified. This implementation requires storing state
-// inside `std::random_device`.
-//
-// _LIBCPP_USING_ARC4_RANDOM
-// Use arc4random(). This allows obtaining random data even when
-// using sandboxing mechanisms. On some platforms like Apple, this
-// is the recommended source of entropy for user-space programs.
-// When this option is used, the token passed to `std::random_device`'s
-// constructor *must* be "/dev/urandom" -- anything else is an error.
-//
-// _LIBCPP_USING_GETENTROPY
-// Use getentropy().
-// When this option is used, the token passed to `std::random_device`'s
-// constructor *must* be "/dev/urandom" -- anything else is an error.
-//
-// _LIBCPP_USING_FUCHSIA_CPRNG
-// Use Fuchsia's zx_cprng_draw() system call, which is specified to
-// deliver high-quality entropy and cannot fail.
-// When this option is used, the token passed to `std::random_device`'s
-// constructor *must* be "/dev/urandom" -- anything else is an error.
-//
-// _LIBCPP_USING_WIN32_RANDOM
-// Use rand_s(), for use on Windows.
-// When this option is used, the token passed to `std::random_device`'s
-// constructor *must* be "/dev/urandom" -- anything else is an error.
-# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
- defined(__DragonFly__)
-# define _LIBCPP_USING_ARC4_RANDOM
-# elif defined(__wasi__) || defined(__EMSCRIPTEN__)
-# define _LIBCPP_USING_GETENTROPY
-# elif defined(__Fuchsia__)
-# define _LIBCPP_USING_FUCHSIA_CPRNG
-# elif defined(_LIBCPP_WIN32API)
-# define _LIBCPP_USING_WIN32_RANDOM
-# else
-# define _LIBCPP_USING_DEV_RANDOM
-# endif
-
# ifndef _LIBCPP_CXX03_LANG
# define _LIBCPP_ALIGNOF(...) alignof(__VA_ARGS__)
@@ -201,107 +157,6 @@ typedef __char32_t char32_t;
# define _LIBCPP_DIAGNOSE_DEPRECATED_HEADERS 0
# endif
-// Thread API
-// clang-format off
-# if _LIBCPP_HAS_THREADS && \
- !_LIBCPP_HAS_THREAD_API_PTHREAD && \
- !_LIBCPP_HAS_THREAD_API_WIN32 && \
- !_LIBCPP_HAS_THREAD_API_EXTERNAL && \
- !_LIBCPP_HAS_THREAD_API_C11
-
-# if defined(__FreeBSD__) || \
- defined(__wasi__) || \
- defined(__NetBSD__) || \
- defined(__OpenBSD__) || \
- defined(__NuttX__) || \
- defined(__linux__) || \
- defined(__GNU__) || \
- defined(__APPLE__) || \
- defined(__MVS__) || \
- defined(_AIX) || \
- defined(__EMSCRIPTEN__)
-// clang-format on
-# undef _LIBCPP_HAS_THREAD_API_PTHREAD
-# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
-# elif defined(__Fuchsia__)
-// TODO(44575): Switch to C11 thread API when possible.
-# undef _LIBCPP_HAS_THREAD_API_PTHREAD
-# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
-# elif defined(_LIBCPP_WIN32API)
-# undef _LIBCPP_HAS_THREAD_API_WIN32
-# define _LIBCPP_HAS_THREAD_API_WIN32 1
-# else
-# error "No thread API"
-# endif // _LIBCPP_HAS_THREAD_API
-# endif // _LIBCPP_HAS_THREADS
-
-# if !_LIBCPP_HAS_THREAD_API_PTHREAD
-# define _LIBCPP_HAS_COND_CLOCKWAIT 0
-# elif (defined(__ANDROID__) && __ANDROID_API__ >= 30) || _LIBCPP_GLIBC_PREREQ(2, 30)
-# define _LIBCPP_HAS_COND_CLOCKWAIT 1
-# else
-# define _LIBCPP_HAS_COND_CLOCKWAIT 0
-# endif
-
-# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
-# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
-# endif
-
-# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
-# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
-# endif
-
-# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_C11
-# error _LIBCPP_HAS_THREAD_API_C11 may only be true when _LIBCPP_HAS_THREADS is true.
-# endif
-
-# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
-# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
-# endif
-
-# if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
-# define __STDCPP_THREADS__ 1
-# endif
-
-// The glibc and Bionic implementation of pthreads implements
-// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
-// mutexes have no destroy mechanism.
-//
-// This optimization can't be performed on Apple platforms, where
-// pthread_mutex_destroy can allow the kernel to release resources.
-// See https://llvm.org/D64298 for details.
-//
-// TODO(EricWF): Enable this optimization on Bionic after speaking to their
-// respective stakeholders.
-// clang-format off
-# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
- (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
- _LIBCPP_HAS_THREAD_API_WIN32
-// clang-format on
-# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
-# else
-# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
-# endif
-
-// Destroying a condvar is a nop on Windows.
-//
-// This optimization can't be performed on Apple platforms, where
-// pthread_cond_destroy can allow the kernel to release resources.
-// See https://llvm.org/D64298 for details.
-//
-// TODO(EricWF): This is potentially true for some pthread implementations
-// as well.
-# if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
-# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
-# else
-# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
-# endif
-
-# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
- _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC
-# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
-# endif
-
// We often repeat things just for handling wide characters in the library.
// When wide characters are disabled, it can be useful to have a quick way of
// disabling it without having to resort to #if-#endif, which has a larger
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index ebd638e663215..5b3bcfa4a8989 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -57,4 +57,148 @@
# define _LIBCPP_BIG_ENDIAN
#endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+// Libc++ supports various implementations of std::random_device.
+//
+// _LIBCPP_USING_DEV_RANDOM
+// Read entropy from the given file, by default `/dev/urandom`.
+// If a token is provided, it is assumed to be the path to a file
+// to read entropy from. This is the default behavior if nothing
+// else is specified. This implementation requires storing state
+// inside `std::random_device`.
+//
+// _LIBCPP_USING_ARC4_RANDOM
+// Use arc4random(). This allows obtaining random data even when
+// using sandboxing mechanisms. On some platforms like Apple, this
+// is the recommended source of entropy for user-space programs.
+// When this option is used, the token passed to `std::random_device`'s
+// constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_GETENTROPY
+// Use getentropy().
+// When this option is used, the token passed to `std::random_device`'s
+// constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_FUCHSIA_CPRNG
+// Use Fuchsia's zx_cprng_draw() system call, which is specified to
+// deliver high-quality entropy and cannot fail.
+// When this option is used, the token passed to `std::random_device`'s
+// constructor *must* be "/dev/urandom" -- anything else is an error.
+//
+// _LIBCPP_USING_WIN32_RANDOM
+// Use rand_s(), for use on Windows.
+// When this option is used, the token passed to `std::random_device`'s
+// constructor *must* be "/dev/urandom" -- anything else is an error.
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+# define _LIBCPP_USING_ARC4_RANDOM
+#elif defined(__wasi__) || defined(__EMSCRIPTEN__)
+# define _LIBCPP_USING_GETENTROPY
+#elif defined(__Fuchsia__)
+# define _LIBCPP_USING_FUCHSIA_CPRNG
+#elif defined(_LIBCPP_WIN32API)
+# define _LIBCPP_USING_WIN32_RANDOM
+#else
+# define _LIBCPP_USING_DEV_RANDOM
+#endif
+
+// Thread API
+// clang-format off
+#if _LIBCPP_HAS_THREADS && \
+ !_LIBCPP_HAS_THREAD_API_PTHREAD && \
+ !_LIBCPP_HAS_THREAD_API_WIN32 && \
+ !_LIBCPP_HAS_THREAD_API_EXTERNAL && \
+ !_LIBCPP_HAS_THREAD_API_C11
+
+# if defined(__FreeBSD__) || \
+ defined(__wasi__) || \
+ defined(__NetBSD__) || \
+ defined(__OpenBSD__) || \
+ defined(__NuttX__) || \
+ defined(__linux__) || \
+ defined(__GNU__) || \
+ defined(__APPLE__) || \
+ defined(__MVS__) || \
+ defined(_AIX) || \
+ defined(__EMSCRIPTEN__)
+// clang-format on
+# undef _LIBCPP_HAS_THREAD_API_PTHREAD
+# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
+# elif defined(__Fuchsia__)
+// TODO(44575): Switch to C11 thread API when possible.
+# undef _LIBCPP_HAS_THREAD_API_PTHREAD
+# define _LIBCPP_HAS_THREAD_API_PTHREAD 1
+# elif defined(_LIBCPP_WIN32API)
+# undef _LIBCPP_HAS_THREAD_API_WIN32
+# define _LIBCPP_HAS_THREAD_API_WIN32 1
+# else
+# error "No thread API"
+# endif // _LIBCPP_HAS_THREAD_API
+#endif // _LIBCPP_HAS_THREADS
+
+#if !_LIBCPP_HAS_THREAD_API_PTHREAD
+# define _LIBCPP_HAS_COND_CLOCKWAIT 0
+#elif (defined(__ANDROID__) && __ANDROID_API__ >= 30) || _LIBCPP_GLIBC_PREREQ(2, 30)
+# define _LIBCPP_HAS_COND_CLOCKWAIT 1
+#else
+# define _LIBCPP_HAS_COND_CLOCKWAIT 0
+#endif
+
+#if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_PTHREAD
+# error _LIBCPP_HAS_THREAD_API_PTHREAD may only be true when _LIBCPP_HAS_THREADS is true.
+#endif
+
+#if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_EXTERNAL
+# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
+#endif
+
+#if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_C11
+# error _LIBCPP_HAS_THREAD_API_C11 may only be true when _LIBCPP_HAS_THREADS is true.
+#endif
+
+#if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
+# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
+#endif
+
+#if _LIBCPP_HAS_THREADS && !defined(__STDCPP_THREADS__)
+# define __STDCPP_THREADS__ 1
+#endif
+
+// The glibc and Bionic implementation of pthreads implements
+// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
+// mutexes have no destroy mechanism.
+//
+// This optimization can't be performed on Apple platforms, where
+// pthread_mutex_destroy can allow the kernel to release resources.
+// See https://llvm.org/D64298 for details.
+//
+// TODO(EricWF): Enable this optimization on Bionic after speaking to their
+// respective stakeholders.
+// clang-format off
+# if (_LIBCPP_HAS_THREAD_API_PTHREAD && defined(__GLIBC__)) || \
+ (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || \
+ _LIBCPP_HAS_THREAD_API_WIN32
+// clang-format on
+# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 1
+#else
+# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION 0
+#endif
+
+// Destroying a condvar is a nop on Windows.
+//
+// This optimization can't be performed on Apple platforms, where
+// pthread_cond_destroy can allow the kernel to release resources.
+// See https://llvm.org/D64298 for details.
+//
+// TODO(EricWF): This is potentially true for some pthread implementations
+// as well.
+#if (_LIBCPP_HAS_THREAD_API_C11 && defined(__Fuchsia__)) || _LIBCPP_HAS_THREAD_API_WIN32
+# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 1
+#else
+# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION 0
+#endif
+
+#if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC || \
+ defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC
+# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
+#endif
+
#endif // _LIBCPP___CONFIGURATION_PLATFORM_H
More information about the libcxx-commits
mailing list