This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [patch] libstdc++/65704 portable timed_mutex and recursive_timed_mutex
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: Torvald Riegel <triegel at redhat dot com>
- Date: Fri, 4 Sep 2015 17:09:17 +0100
- Subject: Re: [patch] libstdc++/65704 portable timed_mutex and recursive_timed_mutex
- Authentication-results: sourceware.org; auth=none
- References: <20150904101819 dot GZ2631 at redhat dot com>
On 04/09/15 11:18 +0100, Jonathan Wakely wrote:
Tested powerpc64le-linux as normal, and again with #undef
_GTHREAD_USE_MUTEX_TIMEDLOCK to test the new code.
Argh, my testing with the 'undef didn't work because <bits/gthr.h> was
included after I had #undef'd it, so I wasn't testing the new code at
all, and it didn't even compile.
This fixes those silly errors, and is really tested now.
Committed to trunk.
commit 293051bb60d30d3da6af6324e13484dc250d8385
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Sep 4 17:06:23 2015 +0100
fix darwin bootstrap errors due to <mutex>.
PR libstdc++/65704
* include/std/mutex (recursive_timed_mutex): Fix uses of _Can_lock.
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 47141d9..38950b6 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -368,9 +368,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Predicate type that tests whether the current thread can lock a mutex.
struct _Can_lock
{
- _Can_lock(const recursive_timed_mutex* __mx)
- : _M_mx(__mx), _M_caller(this_thread::get_id()) { }
-
// Returns true if the mutex is unlocked or is locked by _M_caller.
bool
operator()() const noexcept
@@ -391,7 +388,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
lock()
{
- _Can_lock __can_lock{this};
+ auto __id = this_thread::get_id();
+ _Can_lock __can_lock{this, __id};
unique_lock<mutex> __lk(_M_mut);
_M_cv.wait(__lk, __can_lock);
if (_M_count == -1u)
@@ -403,7 +401,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
try_lock()
{
- _Can_lock __can_lock{this};
+ auto __id = this_thread::get_id();
+ _Can_lock __can_lock{this, __id};
lock_guard<mutex> __lk(_M_mut);
if (!__can_lock())
return false;
@@ -418,9 +417,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
{
- _Can_lock __can_lock{this};
+ auto __id = this_thread::get_id();
+ _Can_lock __can_lock{this, __id};
unique_lock<mutex> __lk(_M_mut);
- if (!_M_cv.wait_for(__lk, __rtime, __can_lock);
+ if (!_M_cv.wait_for(__lk, __rtime, __can_lock))
return false;
if (_M_count == -1u)
return false;
@@ -433,9 +433,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
bool
try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
- _Can_lock __can_lock{this};
+ auto __id = this_thread::get_id();
+ _Can_lock __can_lock{this, __id};
unique_lock<mutex> __lk(_M_mut);
- if (!_M_cv.wait_until(__lk, __atime, __can_lock);
+ if (!_M_cv.wait_until(__lk, __atime, __can_lock))
return false;
if (_M_count == -1u)
return false;