OSDN Git Service

PR libstdc++/53841
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Nov 2012 01:56:05 +0000 (01:56 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 15 Nov 2012 01:56:05 +0000 (01:56 +0000)
* include/std/condition_variable (condition_variable::wait_until):
Handle clocks with higher resolution than __clock_t.
* testsuite/30_threads/condition_variable/members/53841.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@193528 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/condition_variable
libstdc++-v3/testsuite/30_threads/condition_variable/members/53841.cc [new file with mode: 0644]

index 90b1070..8085f24 100644 (file)
@@ -1,3 +1,10 @@
+2012-11-15  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       PR libstdc++/53841
+       * include/std/condition_variable (condition_variable::wait_until):
+       Handle clocks with higher resolution than __clock_t.
+       * testsuite/30_threads/condition_variable/members/53841.cc: New.
+
 2012-11-14  Jonathan Wakely  <jwakely.gcc@gmail.com>
 
        PR libstdc++/55320
index 0a85e1a..60c72ba 100644 (file)
@@ -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);
       }
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 (file)
index 0000000..62e44a6
--- /dev/null
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+// PR libstdc++/53841
+
+#include <chrono>
+#include <mutex>
+#include <condition_variable>
+
+namespace ch = std::chrono;
+
+struct FPClock : ch::system_clock
+{
+    typedef double rep;
+    typedef std::ratio<1> period;
+    typedef ch::duration<rep, period> duration;
+    typedef ch::time_point<FPClock> time_point;
+
+    static time_point now()
+    { return time_point(duration(system_clock::now().time_since_epoch())); }
+};
+
+void f()
+{
+    std::mutex mx;
+    std::unique_lock<std::mutex> l(mx);
+    std::condition_variable cv;
+    cv.wait_until(l, FPClock::now());
+}