Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74551 - trunk/boost/chrono/detail/inlined/posix
From: vicente.botet_at_[hidden]
Date: 2011-09-24 12:10:35


Author: viboes
Date: 2011-09-24 12:10:34 EDT (Sat, 24 Sep 2011)
New Revision: 74551
URL: http://svn.boost.org/trac/boost/changeset/74551

Log:
Chrono: Use CLOCK_PROCESS_CPUTIME_ID when available on posix
Text files modified:
   trunk/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp | 15 +++++++++++++--
   1 files changed, 13 insertions(+), 2 deletions(-)

Modified: trunk/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp (original)
+++ trunk/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp 2011-09-24 12:10:34 EDT (Sat, 24 Sep 2011)
@@ -14,8 +14,9 @@
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/assert.hpp>
 
-# include <sys/times.h>
-# include <unistd.h>
+#include <sys/times.h>
+#include <unistd.h>
+#include <time.h> // for clock_gettime
 
 
 namespace boost { namespace chrono {
@@ -42,7 +43,16 @@
 
 process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
 {
+#if defined(_POSIX_CPUTIME)
+ timespec ts;
+ if ( ::clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ) )
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ }
 
+ return time_point(duration(
+ static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
+#else
     tms tm;
     clock_t c = ::times( &tm );
     if ( c == clock_t(-1) ) // error
@@ -62,6 +72,7 @@
         }
     }
     return time_point();
+#endif
 }
 process_real_cpu_clock::time_point process_real_cpu_clock::now(
         system::error_code & ec)


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk