public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed 2/2] libstdc++: Only include <condition_variable> in <shared_mutex> if needed
Date: Thu, 22 Oct 2020 19:00:41 +0100	[thread overview]
Message-ID: <20201022180041.GA1314079@redhat.com> (raw)
In-Reply-To: <20201022175820.GA1313862@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

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.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3682 bytes --]

commit f5d9bc8ae81abe46640477bc9e655aa093947f5f
Author: Jonathan Wakely <jwakely@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	other threads:[~2020-10-22 18:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 17:59 [committed 1/2] libstdc++: Reduce header dependencies in and on <memory> Jonathan Wakely
2020-10-22 18:00 ` Jonathan Wakely [this message]
2020-10-22 18:06   ` [committed 2/2] libstdc++: Only include <condition_variable> in <shared_mutex> if needed Jonathan Wakely
2020-10-23  0:13 ` [committed 1/2] libstdc++: Reduce header dependencies in and on <memory> Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201022180041.GA1314079@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).