* [PATCH] Reorder std::scoped_lock parameters as per P0739R0 DR status
@ 2017-07-15 15:48 Jonathan Wakely
2017-07-16 13:21 ` Ville Voutilainen
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2017-07-15 15:48 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 661 bytes --]
WG21 just approved this change as a DR for C++17, so that class
template argument deduction works when using std::adopt_lock with a
std::scoped_lock.
* include/std/mutex (scoped_lock): Reorder std::adopt_lock_t parameter
as per P0739R0.
* testsuite/30_threads/scoped_lock/cons/1.cc: Reorder arguments.
* testsuite/30_threads/scoped_lock/cons/deduction.cc: Test deduction
with std::adopt_lock_t.
* testsuite/30_threads/scoped_lock/requirements/typedefs.cc: Check
feature-test macro.
Tested powerpc64le-linux, committed to trunk.
I think we should also make this change and the r250213 one to
std::variant (which is in the same paper) on gcc-7-branch.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4141 bytes --]
commit bd39b9c170c46347e521130ec368964b5977e866
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Jul 15 16:14:48 2017 +0100
Reorder std::scoped_lock parameters as per P0739R0 DR status
* include/std/mutex (scoped_lock): Reorder std::adopt_lock_t parameter
as per P0739R0.
* testsuite/30_threads/scoped_lock/cons/1.cc: Reorder arguments.
* testsuite/30_threads/scoped_lock/cons/deduction.cc: Test deduction
with std::adopt_lock_t.
* testsuite/30_threads/scoped_lock/requirements/typedefs.cc: Check
feature-test macro.
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index df48b46..fadb9f6 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -557,7 +557,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
#if __cplusplus > 201402L
-#define __cpp_lib_scoped_lock 201703
+#define __cpp_lib_scoped_lock 201707
/** @brief A scoped lock type for multiple lockable objects.
*
* A scoped_lock controls mutex ownership within a scope, releasing
@@ -570,7 +570,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
explicit scoped_lock(_MutexTypes&... __m) : _M_devices(std::tie(__m...))
{ std::lock(__m...); }
- explicit scoped_lock(_MutexTypes&... __m, adopt_lock_t) noexcept
+ explicit scoped_lock(adopt_lock_t, _MutexTypes&... __m) noexcept
: _M_devices(std::tie(__m...))
{ } // calling thread owns mutex
@@ -609,7 +609,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
explicit scoped_lock(mutex_type& __m) : _M_device(__m)
{ _M_device.lock(); }
- explicit scoped_lock(mutex_type& __m, adopt_lock_t) noexcept
+ explicit scoped_lock(adopt_lock_t, mutex_type& __m) noexcept
: _M_device(__m)
{ } // calling thread owns mutex
diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc
index 9f1b48c..e420ab0 100644
--- a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc
+++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/1.cc
@@ -79,7 +79,7 @@ void test01()
try
{
- std::scoped_lock<BasicLockable> l(m, std::adopt_lock);
+ std::scoped_lock<BasicLockable> l(std::adopt_lock, m);
}
catch (...)
{
@@ -113,7 +113,7 @@ void test02()
try
{
- std::scoped_lock<Lockable<1>, Lockable<2>> l(m1, m2, std::adopt_lock);
+ std::scoped_lock<Lockable<1>, Lockable<2>> l(std::adopt_lock, m1, m2);
VERIFY( m1.m.locked );
VERIFY( m2.m.locked );
}
diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc
index 399de7a..7d4f5bf 100644
--- a/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc
+++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/cons/deduction.cc
@@ -51,3 +51,28 @@ test01()
std::scoped_lock l2(m2, m3);
check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
}
+
+void
+test02()
+{
+ std::scoped_lock l0(std::adopt_lock);
+ check_type<std::scoped_lock<>>(l0);
+
+ struct BasicLockable {
+ void lock() { }
+ void unlock() { }
+ } m1;
+
+ std::scoped_lock l1(std::adopt_lock, m1);
+ check_type<std::scoped_lock<BasicLockable>>(l1);
+
+ struct Lockable {
+ void lock() { }
+ void unlock() { }
+ bool try_lock() { return true; }
+ } m2;
+
+ std::mutex m3;
+ std::scoped_lock l2(std::adopt_lock, m2, m3);
+ check_type<std::scoped_lock<Lockable, std::mutex>>(l2);
+}
diff --git a/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc b/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc
index 55756d8..0a8903e 100644
--- a/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/30_threads/scoped_lock/requirements/typedefs.cc
@@ -25,6 +25,12 @@
#include <mutex>
+#ifndef __cpp_lib_scoped_lock
+# error "Feature-test macro for scoped_lock missing"
+#elif __cpp_lib_scoped_lock != 201707
+# error "Feature-test macro for scoped_lock has wrong value"
+#endif
+
void test01()
{
// Check for required typedefs
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Reorder std::scoped_lock parameters as per P0739R0 DR status
2017-07-15 15:48 [PATCH] Reorder std::scoped_lock parameters as per P0739R0 DR status Jonathan Wakely
@ 2017-07-16 13:21 ` Ville Voutilainen
0 siblings, 0 replies; 2+ messages in thread
From: Ville Voutilainen @ 2017-07-16 13:21 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
On 15 July 2017 at 18:48, Jonathan Wakely <jwakely@redhat.com> wrote:
> WG21 just approved this change as a DR for C++17, so that class
> template argument deduction works when using std::adopt_lock with a
> std::scoped_lock.
>
> * include/std/mutex (scoped_lock): Reorder std::adopt_lock_t
> parameter
> as per P0739R0.
> * testsuite/30_threads/scoped_lock/cons/1.cc: Reorder arguments.
> * testsuite/30_threads/scoped_lock/cons/deduction.cc: Test deduction
> with std::adopt_lock_t.
> * testsuite/30_threads/scoped_lock/requirements/typedefs.cc: Check
> feature-test macro.
>
> Tested powerpc64le-linux, committed to trunk.
>
> I think we should also make this change and the r250213 one to
> std::variant (which is in the same paper) on gcc-7-branch.
Aye - it doesn't seem sensible to keep the old semantics, our
C++17-support is fairly
fresh.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-07-16 13:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-15 15:48 [PATCH] Reorder std::scoped_lock parameters as per P0739R0 DR status Jonathan Wakely
2017-07-16 13:21 ` Ville Voutilainen
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).