From patchwork Sun Oct 21 14:00:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: A steadier steady_clock Date: Sun, 21 Oct 2012 04:00:20 -0000 From: Sam Varshavchik X-Patchwork-Id: 192996 Message-Id: To: gcc-patches@gcc.gnu.org Based on a casual browsing of clock_gettime(3), CLOCK_MONOTONIC_RAW seems to be a better fit for std::chrono::steady_clock's requirements as given in 20.11.7.2, with recent Linux kernels, Something like this: Index: libstdc++-v3/src/c++11/chrono.cc =================================================================== --- libstdc++-v3/src/c++11/chrono.cc (revision 192652) +++ libstdc++-v3/src/c++11/chrono.cc (working copy) @@ -70,7 +70,11 @@ { timespec tp; // -EINVAL, -EFAULT +#ifdef CLOCK_MONOTONIC_RAW + clock_gettime(CLOCK_MONOTONIC_RAW, &tp); +#else clock_gettime(CLOCK_MONOTONIC, &tp); +#endif return time_point(duration(chrono::seconds(tp.tv_sec) + chrono::nanoseconds(tp.tv_nsec))); }