[libcxx-commits] [libcxx] c4953a0 - [libc++][NFC] Move checks whether mutex/condition_variable are trivial to their headers (#236806)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 30 06:11:36 PDT 2026
Author: Nikolas Klauser
Date: 2026-10-30T14:11:31+01:00
New Revision: c4953a08cd91b86c4f02e9380f43483c8bffcd2b
URL: https://github.com/llvm/llvm-project/commit/c4953a08cd91b86c4f02e9380f43483c8bffcd2b
DIFF: https://github.com/llvm/llvm-project/commit/c4953a08cd91b86c4f02e9380f43483c8bffcd2b.diff
LOG: [libc++][NFC] Move checks whether mutex/condition_variable are trivial to their headers (#236806)
The moved macros are only used as implementation details of `mutex` and
`condition_variable` aren't used widely within the library, so they can
be moved to be more local.
Added:
Modified:
libcxx/include/__condition_variable/condition_variable.h
libcxx/include/__config
libcxx/include/__mutex/mutex.h
Removed:
################################################################################
diff --git a/libcxx/include/__condition_variable/condition_variable.h b/libcxx/include/__condition_variable/condition_variable.h
index 0e1e811d987679..ab3cbdf5711e15 100644
--- a/libcxx/include/__condition_variable/condition_variable.h
+++ b/libcxx/include/__condition_variable/condition_variable.h
@@ -100,6 +100,20 @@ chrono::steady_clock::time_point __rel_to_abs(const _Duration& __rel_time) {
return chrono::steady_clock::now() + chrono::__ceil<chrono::steady_clock::duration>(__rel_time);
}
+// 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
+
class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_WARN_UNUSED condition_variable {
__libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
diff --git a/libcxx/include/__config b/libcxx/include/__config
index ade43d42dc283d..635999f8101745 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -230,38 +230,6 @@ typedef __char32_t char32_t;
# 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.
-//
-// clang-format off
-# if (_LIBCPP_HAS_THREAD_API_PTHREAD && (defined(__GLIBC__) || defined(__BIONIC__))) || \
- (_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
-
// 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/__mutex/mutex.h b/libcxx/include/__mutex/mutex.h
index 699783ec7929d6..e559997489436d 100644
--- a/libcxx/include/__mutex/mutex.h
+++ b/libcxx/include/__mutex/mutex.h
@@ -22,6 +22,24 @@
_LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
+// 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.
+//
+// clang-format off
+# if (_LIBCPP_HAS_THREAD_API_PTHREAD && (defined(__GLIBC__) || defined(__BIONIC__))) || \
+ (_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
+
class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_CAPABILITY("mutex") _LIBCPP_WARN_UNUSED mutex {
__libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
More information about the libcxx-commits
mailing list