[libcxx-commits] [libcxx] [libc++] Move threading and random device config into <__configuration/platform.h> (PR #206262)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 27 09:21:50 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
These are platform-specific configuration options, so they should live `<__configuration/platform.h>`.
---
Full diff: https://github.com/llvm/llvm-project/pull/206262.diff
2 Files Affected:
- (modified) libcxx/include/__config (-145)
- (modified) libcxx/include/__configuration/platform.h (+145)
``````````diff
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..f24319fa2741f 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -57,4 +57,149 @@
# 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/206262
More information about the libcxx-commits
mailing list