[libcxx-commits] [libcxx] [libc++][NFC] Move checks whether mutex/condition_variable are trivial to their headers (PR #236806)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Oct 30 06:12:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/236806.diff
3 Files Affected:
- (modified) libcxx/include/__condition_variable/condition_variable.h (+14)
- (modified) libcxx/include/__config (-32)
- (modified) libcxx/include/__mutex/mutex.h (+18)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/236806
More information about the libcxx-commits
mailing list