From: Jonathan Wakely Date: Thu, 15 Nov 2012 01:38:17 +0000 (+0000) Subject: re PR libstdc++/53841 ([C++11] condition_variable::wait_until() fails with high resol... X-Git-Tag: upstream/12.2.0~72806 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c25639b1a3aaf288a1fb5b6b6921defa7e5dfa4a;p=platform%2Fupstream%2Fgcc.git re PR libstdc++/53841 ([C++11] condition_variable::wait_until() fails with high resolution clocks) PR libstdc++/53841 * include/std/condition_variable (condition_variable::wait_until): Handle clocks with higher resolution than __clock_t. (condition_variable::__wait_until_impl): Remove unnecessary _Clock parameter. * testsuite/30_threads/condition_variable/members/53841.cc: New. From-SVN: r193523 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c9c6317..a75e97a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2012-11-15 Jonathan Wakely + + PR libstdc++/53841 + * include/std/condition_variable (condition_variable::wait_until): + Handle clocks with higher resolution than __clock_t. + (condition_variable::__wait_until_impl): Remove unnecessary _Clock + parameter. + * testsuite/30_threads/condition_variable/members/53841.cc: New. + 2012-11-14 Jonathan Wakely PR libstdc++/55320 diff --git a/libstdc++-v3/include/std/condition_variable b/libstdc++-v3/include/std/condition_variable index a58d7f5..7d3d622 100644 --- a/libstdc++-v3/include/std/condition_variable +++ b/libstdc++-v3/include/std/condition_variable @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. +// Copyright (C) 2008-2012 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -107,8 +107,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // DR 887 - Sync unknown clock to known clock. const typename _Clock::time_point __c_entry = _Clock::now(); const __clock_t::time_point __s_entry = __clock_t::now(); - const chrono::nanoseconds __delta = __atime - __c_entry; - const __clock_t::time_point __s_atime = __s_entry + __delta; + const auto __delta = __atime - __c_entry; + const auto __s_atime = __s_entry + __delta; return __wait_until_impl(__lock, __s_atime); } @@ -143,16 +143,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return &_M_cond; } private: - template + template cv_status __wait_until_impl(unique_lock& __lock, - const chrono::time_point<_Clock, _Duration>& __atime) + const chrono::time_point<__clock_t, _Dur>& __atime) { - chrono::time_point<__clock_t, chrono::seconds> __s = - chrono::time_point_cast(__atime); - - chrono::nanoseconds __ns = - chrono::duration_cast(__atime - __s); + auto __s = chrono::time_point_cast(__atime); + auto __ns = chrono::duration_cast(__atime - __s); __gthread_time_t __ts = { @@ -163,7 +160,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(), &__ts); - return (_Clock::now() < __atime + return (__clock_t::now() < __atime ? cv_status::no_timeout : cv_status::timeout); } }; diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable/members/53841.cc b/libstdc++-v3/testsuite/30_threads/condition_variable/members/53841.cc new file mode 100644 index 0000000..62e44a6 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/condition_variable/members/53841.cc @@ -0,0 +1,50 @@ +// { dg-do compile } +// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* powerpc-ibm-aix* } } +// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } } +// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } + +// Copyright (C) 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// PR libstdc++/53841 + +#include +#include +#include + +namespace ch = std::chrono; + +struct FPClock : ch::system_clock +{ + typedef double rep; + typedef std::ratio<1> period; + typedef ch::duration duration; + typedef ch::time_point time_point; + + static time_point now() + { return time_point(duration(system_clock::now().time_since_epoch())); } +}; + +void f() +{ + std::mutex mx; + std::unique_lock l(mx); + std::condition_variable cv; + cv.wait_until(l, FPClock::now()); +}