[libcxx-commits] [libcxx] [libc++] Granularize <mutex> includes (PR #117068)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 20 14:06:32 PST 2024


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/117068

None

>From 0d1e86059f683015a6e3a57f2f114fab471e134f Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 20 Nov 2024 23:06:12 +0100
Subject: [PATCH] [libc++] Granularize <mutex> includes

---
 libcxx/include/__memory_resource/synchronized_pool_resource.h | 3 ++-
 libcxx/include/future                                         | 2 +-
 libcxx/include/memory_resource                                | 4 ++++
 libcxx/include/syncstream                                     | 2 +-
 libcxx/test/libcxx/transitive_includes/cxx23.csv              | 4 ----
 libcxx/test/libcxx/transitive_includes/cxx26.csv              | 4 ----
 6 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/libcxx/include/__memory_resource/synchronized_pool_resource.h b/libcxx/include/__memory_resource/synchronized_pool_resource.h
index 6384564afc917a..1533fa6f794e1b 100644
--- a/libcxx/include/__memory_resource/synchronized_pool_resource.h
+++ b/libcxx/include/__memory_resource/synchronized_pool_resource.h
@@ -13,7 +13,8 @@
 #include <__memory_resource/memory_resource.h>
 #include <__memory_resource/pool_options.h>
 #include <__memory_resource/unsynchronized_pool_resource.h>
-#include <mutex>
+#include <__mutex/mutex.h>
+#include <__mutex/unique_lock.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
diff --git a/libcxx/include/future b/libcxx/include/future
index cbf3ed93464176..b6bd89534d2797 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -381,6 +381,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #  include <__memory/shared_count.h>
 #  include <__memory/unique_ptr.h>
 #  include <__memory/uses_allocator.h>
+#  include <__mutex/lock_guard.h>
 #  include <__system_error/error_category.h>
 #  include <__system_error/error_code.h>
 #  include <__system_error/error_condition.h>
@@ -395,7 +396,6 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #  include <__utility/auto_cast.h>
 #  include <__utility/forward.h>
 #  include <__utility/move.h>
-#  include <mutex>
 #  include <new>
 #  include <stdexcept>
 #  include <version>
diff --git a/libcxx/include/memory_resource b/libcxx/include/memory_resource
index 7de69e67b7c062..e54b7e6e2473fe 100644
--- a/libcxx/include/memory_resource
+++ b/libcxx/include/memory_resource
@@ -66,6 +66,10 @@ namespace std::pmr {
 #  pragma GCC system_header
 #endif
 
+#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER >= 17 && _LIBCPP_STD_VER <= 20
+#  include <mutex>
+#endif
+
 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #  include <stdexcept>
 #endif
diff --git a/libcxx/include/syncstream b/libcxx/include/syncstream
index 970706976e1ff1..2699a4b3a6fbbd 100644
--- a/libcxx/include/syncstream
+++ b/libcxx/include/syncstream
@@ -121,6 +121,7 @@ namespace std {
 
 #if _LIBCPP_HAS_LOCALIZATION
 
+#  include <__mutex/lock_guard.h>
 #  include <__utility/move.h>
 #  include <ios>
 #  include <iosfwd> // required for declaration of default arguments
@@ -129,7 +130,6 @@ namespace std {
 
 #  if _LIBCPP_HAS_THREADS
 #    include <map>
-#    include <mutex>
 #    include <shared_mutex>
 #  endif
 
diff --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index a008b4d76edde6..096c321672474d 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -465,7 +465,6 @@ future iosfwd
 future istream
 future limits
 future locale
-future mutex
 future new
 future ratio
 future sstream
@@ -692,11 +691,9 @@ memory_resource compare
 memory_resource cstdint
 memory_resource ctime
 memory_resource limits
-memory_resource mutex
 memory_resource new
 memory_resource ratio
 memory_resource tuple
-memory_resource typeinfo
 memory_resource version
 mutex cerrno
 mutex climits
@@ -1076,7 +1073,6 @@ syncstream iosfwd
 syncstream limits
 syncstream locale
 syncstream map
-syncstream mutex
 syncstream new
 syncstream optional
 syncstream ostream
diff --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index d5321da32b3d46..74d912e5fe3a31 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -464,7 +464,6 @@ future iosfwd
 future istream
 future limits
 future locale
-future mutex
 future new
 future ratio
 future sstream
@@ -691,11 +690,9 @@ memory_resource compare
 memory_resource cstdint
 memory_resource ctime
 memory_resource limits
-memory_resource mutex
 memory_resource new
 memory_resource ratio
 memory_resource tuple
-memory_resource typeinfo
 memory_resource version
 mutex cerrno
 mutex climits
@@ -1075,7 +1072,6 @@ syncstream iosfwd
 syncstream limits
 syncstream locale
 syncstream map
-syncstream mutex
 syncstream new
 syncstream optional
 syncstream ostream



More information about the libcxx-commits mailing list