The <condition_variable> header is not small, so <shared_mutex> should
not include it unless it actually needs std::condition_variable, which
is only the case when we don't have pthread_rwlock_t and the POSIX
Timers option.

The <shared_mutex> header would be even smaller if we had a header for
std::condition_variable (separate from std::condition_variable_any).
That's already planned for a future change.

And <memory_resource> would be even smaller if it was possible to get
std::shared_mutex without std::shared_timed_mutex (which depends on
<chrono>). For that to be effective, the synchronized_pool_resource
would have to create its own simpler version of std::shared_lock without
the timed waiting functions. I have no plans to do that.

libstdc++-v3/ChangeLog:

        * include/std/shared_mutex: Only include <condition_variable>
        when pthread_rwlock_t and POSIX timers are not available.
        (__cpp_lib_shared_mutex, __cpp_lib_shared_timed_mutex): Change
        value to be type 'long'.
        * include/std/version (__cpp_lib_shared_mutex)
        (__cpp_lib_shared_timed_mutex): Likewise.


Tested powerpc64le-linux. Committed to trunk.


commit f5d9bc8ae81abe46640477bc9e655aa093947f5f
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Oct 22 18:42:03 2020

    libstdc++: Only include <condition_variable> in <shared_mutex> if needed
    
    The <condition_variable> header is not small, so <shared_mutex> should
    not include it unless it actually needs std::condition_variable, which
    is only the case when we don't have pthread_rwlock_t and the POSIX
    Timers option.
    
    The <shared_mutex> header would be even smaller if we had a header for
    std::condition_variable (separate from std::condition_variable_any).
    That's already planned for a future change.
    
    And <memory_resource> would be even smaller if it was possible to get
    std::shared_mutex without std::shared_timed_mutex (which depends on
    <chrono>). For that to be effective, the synchronized_pool_resource
    would have to create its own simpler version of std::shared_lock without
    the timed waiting functions. I have no plans to do that.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/shared_mutex: Only include <condition_variable>
            when pthread_rwlock_t and POSIX timers are not available.
            (__cpp_lib_shared_mutex, __cpp_lib_shared_timed_mutex): Change
            value to be type 'long'.
            * include/std/version (__cpp_lib_shared_mutex)
            (__cpp_lib_shared_timed_mutex): Likewise.

diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex
index 414dce3a1b7..7d683a0e0c4 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -33,9 +33,14 @@
 
 #if __cplusplus >= 201402L
 
-#include <bits/c++config.h>
-#include <condition_variable>
+#include <chrono>
 #include <bits/functexcept.h>
+#include <bits/move.h>        // move, __exchange
+#include <bits/std_mutex.h>   // defer_lock_t
+
+#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
+# include <condition_variable>
+#endif
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
@@ -49,11 +54,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #ifdef _GLIBCXX_HAS_GTHREADS
 
 #if __cplusplus >= 201703L
-#define __cpp_lib_shared_mutex 201505
+#define __cpp_lib_shared_mutex 201505L
   class shared_mutex;
 #endif
 
-#define __cpp_lib_shared_timed_mutex 201402
+#define __cpp_lib_shared_timed_mutex 201402L
   class shared_timed_mutex;
 
   /// @cond undocumented
@@ -399,7 +404,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
   /// @endcond
 
-#if __cplusplus > 201402L
+#if __cplusplus >= 201703L
   /// The standard shared mutex type.
   class shared_mutex
   {
@@ -814,7 +819,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       release() noexcept
       {
 	_M_owns = false;
-	return std::exchange(_M_pm, nullptr);
+	return std::__exchange(_M_pm, nullptr);
       }
 
       // Getters
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 9c16f2c4e70..ebb50a04d24 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -89,7 +89,7 @@
 # define __cpp_lib_quoted_string_io 201304
 # define __cpp_lib_robust_nonmodifying_seq_ops 201304
 # ifdef _GLIBCXX_HAS_GTHREADS
-#  define __cpp_lib_shared_timed_mutex 201402
+#  define __cpp_lib_shared_timed_mutex 201402L
 # endif
 # define __cpp_lib_string_udls 201304
 # define __cpp_lib_transparent_operators 201510
@@ -157,7 +157,7 @@
 #define __cpp_lib_sample 201603
 #ifdef _GLIBCXX_HAS_GTHREADS
 # define __cpp_lib_scoped_lock 201703
-# define __cpp_lib_shared_mutex 201505
+# define __cpp_lib_shared_mutex 201505L
 #endif
 #define __cpp_lib_shared_ptr_weak_type 201606
 #define __cpp_lib_string_view 201803L

Reply via email to