mirror of git://gcc.gnu.org/git/gcc.git
re PR libstdc++/54562 (mutex and condition variable timers)
PR libstdc++/54562 * include/std/mutex (__timed_mutex_impl::__clock_t): Use high_resolution_clock for absolute timeouts, because pthread_mutex_timedlock uses CLOCK_REALTIME not CLOCK_MONOTONIC. (__timed_mutex_impl::_M_try_lock_for): Use steady_clock for relative timeouts as per [thread.req.timing]. (__timed_mutex_impl::_M_try_lock_until<Clock,Duration>): Convert to __clock_t time point instead of using _M_try_lock_for. From-SVN: r204672
This commit is contained in:
parent
1a80085d42
commit
6162239973
|
|
@ -1,3 +1,14 @@
|
||||||
|
2013-11-11 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||||
|
|
||||||
|
PR libstdc++/54562
|
||||||
|
* include/std/mutex (__timed_mutex_impl::__clock_t): Use
|
||||||
|
high_resolution_clock for absolute timeouts, because
|
||||||
|
pthread_mutex_timedlock uses CLOCK_REALTIME not CLOCK_MONOTONIC.
|
||||||
|
(__timed_mutex_impl::_M_try_lock_for): Use steady_clock for relative
|
||||||
|
timeouts as per [thread.req.timing].
|
||||||
|
(__timed_mutex_impl::_M_try_lock_until<Clock,Duration>): Convert to
|
||||||
|
__clock_t time point instead of using _M_try_lock_for.
|
||||||
|
|
||||||
2013-11-09 Jonathan Wakely <jwakely.gcc@gmail.com>
|
2013-11-09 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||||
|
|
||||||
PR libstdc++/58982
|
PR libstdc++/58982
|
||||||
|
|
|
||||||
|
|
@ -203,21 +203,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
class __timed_mutex_impl
|
class __timed_mutex_impl
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
#ifdef _GLIBCXX_USE_CLOCK_MONOTONIC
|
|
||||||
typedef chrono::steady_clock __clock_t;
|
|
||||||
#else
|
|
||||||
typedef chrono::high_resolution_clock __clock_t;
|
typedef chrono::high_resolution_clock __clock_t;
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename _Rep, typename _Period>
|
template<typename _Rep, typename _Period>
|
||||||
bool
|
bool
|
||||||
_M_try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
|
_M_try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
|
||||||
{
|
{
|
||||||
auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
|
using chrono::steady_clock;
|
||||||
if (ratio_greater<__clock_t::period, _Period>())
|
auto __rt = chrono::duration_cast<steady_clock::duration>(__rtime);
|
||||||
|
if (ratio_greater<steady_clock::period, _Period>())
|
||||||
++__rt;
|
++__rt;
|
||||||
|
return _M_try_lock_until(steady_clock::now() + __rt);
|
||||||
return _M_try_lock_until(__clock_t::now() + __rt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Duration>
|
template<typename _Duration>
|
||||||
|
|
@ -225,11 +221,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
_M_try_lock_until(const chrono::time_point<__clock_t,
|
_M_try_lock_until(const chrono::time_point<__clock_t,
|
||||||
_Duration>& __atime)
|
_Duration>& __atime)
|
||||||
{
|
{
|
||||||
chrono::time_point<__clock_t, chrono::seconds> __s =
|
auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
|
||||||
chrono::time_point_cast<chrono::seconds>(__atime);
|
auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
|
||||||
|
|
||||||
chrono::nanoseconds __ns =
|
|
||||||
chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
|
|
||||||
|
|
||||||
__gthread_time_t __ts = {
|
__gthread_time_t __ts = {
|
||||||
static_cast<std::time_t>(__s.time_since_epoch().count()),
|
static_cast<std::time_t>(__s.time_since_epoch().count()),
|
||||||
|
|
@ -243,7 +236,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
template<typename _Clock, typename _Duration>
|
template<typename _Clock, typename _Duration>
|
||||||
bool
|
bool
|
||||||
_M_try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
|
_M_try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
|
||||||
{ return _M_try_lock_for(__atime - _Clock::now()); }
|
{
|
||||||
|
auto __rtime = __atime - _Clock::now();
|
||||||
|
return _M_try_lock_until(__clock_t::now() + __rtime);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// timed_mutex
|
/// timed_mutex
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue