Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74549 - trunk/boost/chrono/detail/inlined/win
From: vicente.botet_at_[hidden]
Date: 2011-09-24 12:00:17


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

Log:
Chrono: Use clock() instead of steady_clock to represent wall process clock on windows
Text files modified:
   trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp | 146 +++++++++++++--------------------------
   1 files changed, 49 insertions(+), 97 deletions(-)

Modified: trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp (original)
+++ trunk/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp 2011-09-24 12:00:17 EDT (Sat, 24 Sep 2011)
@@ -16,6 +16,7 @@
 //#include <boost/chrono/system_clocks.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <cassert>
+#include <time.h>
 
 #include <boost/detail/win/GetLastError.hpp>
 #include <boost/detail/win/GetCurrentProcess.hpp>
@@ -28,70 +29,35 @@
 
 process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
 {
-
- // note that Windows uses 100 nanosecond ticks for FILETIME
- boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
-
- if ( boost::detail::win32::GetProcessTimes(
- boost::detail::win32::GetCurrentProcess(), &creation, &exit,
- &system_time, &user_time ) )
- {
- return time_point(duration(
- ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
- | user_time.dwLowDateTime) * 100
- +
- ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
- | system_time.dwLowDateTime) * 100
- ));
- }
- else
+ clock_t c = ::clock();
+ if ( c == clock_t(-1) ) // error
     {
       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
     }
- return time_point();
+ return time_point(
+ duration(c*(1000000000l/CLOCKS_PER_SEC))
+ );
 }
 
 process_real_cpu_clock::time_point process_real_cpu_clock::now(
- system::error_code & ec)
+ system::error_code & ec)
 {
-
- // note that Windows uses 100 nanosecond ticks for FILETIME
- boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
-
- if ( boost::detail::win32::GetProcessTimes(
- boost::detail::win32::GetCurrentProcess(), &creation, &exit,
- &system_time, &user_time ) )
- {
- if (!BOOST_CHRONO_IS_THROWS(ec))
- {
- ec.clear();
- }
- return time_point(duration(
- ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
- | user_time.dwLowDateTime) * 100
- +
- ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
- | system_time.dwLowDateTime) * 100
- ));
- }
- else
+ clock_t c = ::clock();
+ if ( c == clock_t(-1) ) // error
     {
- boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
- if (BOOST_CHRONO_IS_THROWS(ec))
- {
             boost::throw_exception(
- system::system_error(
- cause,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_real_cpu_clock" ));
- }
- else
- {
- ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
- return time_point();
- }
     }
-
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(
+ duration(c*(1000000000l/CLOCKS_PER_SEC))
+ );
 }
 
 process_user_cpu_clock::time_point process_user_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
@@ -118,7 +84,7 @@
 }
 
 process_user_cpu_clock::time_point process_user_cpu_clock::now(
- system::error_code & ec)
+ system::error_code & ec)
 {
 
     // note that Windows uses 100 nanosecond ticks for FILETIME
@@ -128,7 +94,7 @@
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
     {
- if (!BOOST_CHRONO_IS_THROWS(ec))
+ if (!BOOST_CHRONO_IS_THROWS(ec))
         {
             ec.clear();
         }
@@ -140,15 +106,15 @@
     else
     {
         boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
- if (BOOST_CHRONO_IS_THROWS(ec))
+ if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
- system::system_error(
- cause,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ cause,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_user_cpu_clock" ));
- }
- else
+ }
+ else
         {
             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
             return time_point();
@@ -181,7 +147,7 @@
 }
 
 process_system_cpu_clock::time_point process_system_cpu_clock::now(
- system::error_code & ec)
+ system::error_code & ec)
 {
 
     // note that Windows uses 100 nanosecond ticks for FILETIME
@@ -191,7 +157,7 @@
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
     {
- if (!BOOST_CHRONO_IS_THROWS(ec))
+ if (!BOOST_CHRONO_IS_THROWS(ec))
         {
             ec.clear();
         }
@@ -203,21 +169,21 @@
     else
     {
         boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
- if (BOOST_CHRONO_IS_THROWS(ec))
+ if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
- system::system_error(
- cause,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ cause,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_system_cpu_clock" ));
- }
- else
+ }
+ else
         {
             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
             return time_point();
         }
     }
-
+
 }
 process_cpu_clock::time_point process_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
 {
@@ -229,14 +195,7 @@
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
     {
- time_point::rep r(
- ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
- | user_time.dwLowDateTime
- ) * 100
- +
- ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
- | system_time.dwLowDateTime
- ) * 100
+ time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
                             ,
                 ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
                         | user_time.dwLowDateTime
@@ -255,8 +214,8 @@
 
 }
 
-process_cpu_clock::time_point process_cpu_clock::now(
- system::error_code & ec )
+process_cpu_clock::time_point process_cpu_clock::now(
+ system::error_code & ec )
 {
 
     // note that Windows uses 100 nanosecond ticks for FILETIME
@@ -266,40 +225,33 @@
             boost::detail::win32::GetCurrentProcess(), &creation, &exit,
             &system_time, &user_time ) )
     {
- if (!BOOST_CHRONO_IS_THROWS(ec))
+ if (!BOOST_CHRONO_IS_THROWS(ec))
         {
             ec.clear();
         }
- time_point::rep r(
- ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
- | user_time.dwLowDateTime
- ) * 100
- +
- ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
- | system_time.dwLowDateTime
- ) * 100
+ time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
                             ,
                 ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
                         | user_time.dwLowDateTime
- ) * 100,
+ ) * 100,
                 ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
                         | system_time.dwLowDateTime
- ) * 100
+ ) * 100
         );
         return time_point(duration(r));
     }
     else
     {
         boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
- if (BOOST_CHRONO_IS_THROWS(ec))
+ if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
- system::system_error(
- cause,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ cause,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_cpu_clock" ));
- }
- else
+ }
+ else
         {
             ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
             return time_point();


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