]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Restore std::scoped_lock for non-gthreads targets [PR120198]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 9 May 2025 16:50:52 +0000 (17:50 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 13 May 2025 11:05:48 +0000 (12:05 +0100)
This was a regression introduced with using version.def to define
feature test macros (r14-3248-g083b7f2833d71d). std::scoped_lock doesn't
need to depend on gthreads and so can be defined unconditionally, even
for freestanding.

libstdc++-v3/ChangeLog:

PR libstdc++/120198
* include/bits/version.def (scoped_lock): Do not depend on
gthreads or hosted.
* include/bits/version.h: Regenerate.
* include/std/mutex (scoped_lock): Update comment.
* testsuite/30_threads/scoped_lock/requirements/typedefs.cc:
Remove dg-require-gthreads and use custom lockable type instead
of std::mutex. Check that typedef is only present for a single
template argument.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
(cherry picked from commit bdd2753f5f021a15a6c4ef02565356985fea1300)

libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/mutex
libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc

index 91c144cc4f0a0fb7c59e34e5cd09e16638724cf2..49c0a0a9fc0652815e723506ff005e0221d0a038 100644 (file)
@@ -668,8 +668,6 @@ ftms = {
   values = {
     v = 201703;
     cxxmin = 17;
-    hosted = yes;
-    gthread = yes;
   };
 };
 
index 82901af2ad627483af4035e93de399a4a86979e5..5c6d8a9f8afc31a5226a0abb79c69998f5b94be4 100644 (file)
 #undef __glibcxx_want_parallel_algorithm
 
 #if !defined(__cpp_lib_scoped_lock)
-# if (__cplusplus >= 201703L) && defined(_GLIBCXX_HAS_GTHREADS) && _GLIBCXX_HOSTED
+# if (__cplusplus >= 201703L)
 #  define __glibcxx_scoped_lock 201703L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_scoped_lock)
 #   define __cpp_lib_scoped_lock 201703L
index 8dd9b23191fd7c17c4e3392a8ef63dec9d063371..e4b14c0172010fc9076c3ec16d4638c5383caa63 100644 (file)
@@ -731,7 +731,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     }
 
-#ifdef __cpp_lib_scoped_lock // C++ >= 17 && hosted && gthread
+#ifdef __cpp_lib_scoped_lock // C++ >= 17
   /** @brief A scoped lock type for multiple lockable objects.
    *
    * A scoped_lock controls mutex ownership within a scope, releasing
index 5ee9104b17d47bc7346ab3de199028ca0bfcdf43..335b8e79147119dc4b9f22a22d189d2d4622fc77 100644 (file)
@@ -1,5 +1,4 @@
 // { dg-do compile { target c++17 } }
-// { dg-require-gthreads "" }
 // { dg-add-options no_pch }
 
 // Copyright (C) 2017-2024 Free Software Foundation, Inc.
 # error "Feature-test macro for scoped_lock has wrong value"
 #endif
 
+struct BasicLockable
+{
+  BasicLockable() = default;
+  ~BasicLockable() = default;
+  void lock() { }
+  void unlock() { }
+};
+
 void test01()
 {
-  // Check for required typedefs
-  typedef std::scoped_lock<std::mutex> test_type;
-  typedef test_type::mutex_type mutex_type;
+  // Check for required typedef.
+  using test_type = std::scoped_lock<BasicLockable>;
+  static_assert(std::is_same_v<test_type::mutex_type, BasicLockable>);
+}
+
+template<typename T, typename = void>
+constexpr bool has_mutex_type = false;
+
+template<typename T>
+constexpr bool has_mutex_type<T, std::void_t<typename T::mutex_type>> = true;
+
+void test02()
+{
+  // Check that typedef is absent as required.
+  using test_type = std::scoped_lock<BasicLockable, BasicLockable>;
+  static_assert(!has_mutex_type<test_type>);
 }