Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77694 - in branches/release/boost/chrono/detail/inlined: posix win
From: vicente.botet_at_[hidden]
Date: 2012-04-01 15:28:17


Author: viboes
Date: 2012-04-01 15:28:17 EDT (Sun, 01 Apr 2012)
New Revision: 77694
URL: http://svn.boost.org/trac/boost/changeset/77694

Log:
Chrono Fix #6361,#6628,#6666
Text files modified:
   branches/release/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp | 67 ++++++++++++++++++++-------------------
   branches/release/boost/chrono/detail/inlined/posix/thread_clock.hpp | 11 +++--
   branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp | 6 ++-
   3 files changed, 44 insertions(+), 40 deletions(-)

Modified: branches/release/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp
==============================================================================
--- branches/release/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp (original)
+++ branches/release/boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp 2012-04-01 15:28:17 EDT (Sun, 01 Apr 2012)
@@ -32,8 +32,8 @@
         factor = -1;
       else
       {
- BOOST_ASSERT( factor <= 1000000l ); // doesn't handle large ticks
- factor = 1000000l / factor; // compute factor
+ BOOST_ASSERT( factor <= 1000000000l ); // doesn't handle large ticks
+ factor = 1000000000l / factor; // compute factor
         if ( !factor ) factor = -1;
       }
     }
@@ -54,7 +54,7 @@
         if ( chrono_detail::tick_factor() != -1 )
         {
             return time_point(
- microseconds(c*chrono_detail::tick_factor()));
+ nanoseconds(c*chrono_detail::tick_factor()));
         }
         else
         {
@@ -66,9 +66,9 @@
 
 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
 process_real_cpu_clock::time_point process_real_cpu_clock::now(
- system::error_code & ec)
+ system::error_code & ec)
 {
-
+
     tms tm;
     clock_t c = ::times( &tm );
     if ( c == clock_t(-1) ) // error
@@ -76,9 +76,9 @@
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_real_cpu_clock" ));
         }
         else
@@ -91,21 +91,21 @@
     {
         if ( chrono_detail::tick_factor() != -1 )
         {
- if (!BOOST_CHRONO_IS_THROWS(ec))
+ if (!BOOST_CHRONO_IS_THROWS(ec))
             {
                 ec.clear();
             }
             return time_point(
- microseconds(c*chrono_detail::tick_factor()));
+ nanoseconds(c*chrono_detail::tick_factor()));
         }
         else
         {
             if (BOOST_CHRONO_IS_THROWS(ec))
             {
                 boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                                 "chrono::process_real_cpu_clock" ));
             }
             else
@@ -131,7 +131,7 @@
         if ( chrono_detail::tick_factor() != -1 )
         {
             return time_point(
- microseconds((tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor()));
+ nanoseconds((tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor()));
         }
         else
         {
@@ -152,9 +152,9 @@
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_user_cpu_clock" ));
         }
         else
@@ -167,21 +167,21 @@
     {
         if ( chrono_detail::tick_factor() != -1 )
         {
- if (!BOOST_CHRONO_IS_THROWS(ec))
+ if (!BOOST_CHRONO_IS_THROWS(ec))
             {
                 ec.clear();
             }
             return time_point(
- microseconds((tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor()));
+ nanoseconds((tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor()));
         }
         else
         {
             if (BOOST_CHRONO_IS_THROWS(ec))
             {
                 boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                                 "chrono::process_user_cpu_clock" ));
             }
             else
@@ -208,11 +208,12 @@
         if ( chrono_detail::tick_factor() != -1 )
         {
             return time_point(
- microseconds((tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()));
+ nanoseconds((tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()));
         }
         else
         {
           BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ return time_point();
         }
     }
 }
@@ -248,7 +249,7 @@
                 ec.clear();
             }
             return time_point(
- microseconds((tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()));
+ nanoseconds((tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor()));
         }
         else
         {
@@ -297,8 +298,8 @@
 }
 
 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
-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 )
 {
     tms tm;
     clock_t c = ::times( &tm );
@@ -307,9 +308,9 @@
         if (BOOST_CHRONO_IS_THROWS(ec))
         {
             boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                             "chrono::process_clock" ));
         }
         else
@@ -333,9 +334,9 @@
             if (BOOST_CHRONO_IS_THROWS(ec))
             {
                 boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                                 "chrono::process_clock" ));
             }
             else
@@ -345,7 +346,7 @@
             }
         }
     }
-
+
 }
 #endif
 

Modified: branches/release/boost/chrono/detail/inlined/posix/thread_clock.hpp
==============================================================================
--- branches/release/boost/chrono/detail/inlined/posix/thread_clock.hpp (original)
+++ branches/release/boost/chrono/detail/inlined/posix/thread_clock.hpp 2012-04-01 15:28:17 EDT (Sun, 01 Apr 2012)
@@ -15,6 +15,7 @@
 #include <cassert>
 
 # include <sys/times.h>
+# include <pthread.h>
 # include <unistd.h>
 
 namespace boost { namespace chrono {
@@ -45,7 +46,7 @@
     }
 
 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
- thread_clock::time_point thread_clock::now( system::error_code & ec )
+ thread_clock::time_point thread_clock::now( system::error_code & ec )
     {
       struct timespec ts;
 #if defined CLOCK_THREAD_CPUTIME_ID
@@ -64,9 +65,9 @@
             if (BOOST_CHRONO_IS_THROWS(ec))
             {
                 boost::throw_exception(
- system::system_error(
- errno,
- BOOST_CHRONO_SYSTEM_CATEGORY,
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
                                 "chrono::thread_clock" ));
             }
             else
@@ -75,7 +76,7 @@
                 return time_point();
             }
         }
- if (!BOOST_CHRONO_IS_THROWS(ec))
+ if (!BOOST_CHRONO_IS_THROWS(ec))
         {
             ec.clear();
         }

Modified: branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp
==============================================================================
--- branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp (original)
+++ branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp 2012-04-01 15:28:17 EDT (Sun, 01 Apr 2012)
@@ -34,8 +34,9 @@
     {
       BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
     }
+ typedef ratio_divide<giga, ratio<CLOCKS_PER_SEC> >::type R;
     return time_point(
- duration(c*(1000000000l/CLOCKS_PER_SEC))
+ duration(static_cast<rep>(c)*R::num/R::den)
     );
 }
 
@@ -56,8 +57,9 @@
     {
       ec.clear();
     }
+ typedef ratio_divide<giga, ratio<CLOCKS_PER_SEC> >::type R;
     return time_point(
- duration(c*(1000000000l/CLOCKS_PER_SEC))
+ duration(static_cast<rep>(c)*R::num/R::den)
     );
 }
 #endif


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