$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r74450 - in trunk/boost/chrono: . detail/inlined/mac stopwatches
From: vicente.botet_at_[hidden]
Date: 2011-09-18 10:09:58
Author: viboes
Date: 2011-09-18 10:09:56 EDT (Sun, 18 Sep 2011)
New Revision: 74450
URL: http://svn.boost.org/trac/boost/changeset/74450
Log:
Chrono: fixed #5909: process_cpu_clock::now() on MAC gives time_points 1/1000 times + improve simple_stopwatch
Text files modified: 
   trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp |    27 ++++++++++++++-------------             
   trunk/boost/chrono/process_cpu_clocks.hpp                    |     9 +++++++++                               
   trunk/boost/chrono/stopwatches/simple_stopwatch.hpp          |    32 +++++++++++++++++++++++++++++---        
   trunk/boost/chrono/system_clocks.hpp                         |     8 ++++----                                
   trunk/boost/chrono/thread_clock.hpp                          |     7 ++++---                                 
   5 files changed, 60 insertions(+), 23 deletions(-)
Modified: trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp	(original)
+++ trunk/boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp	2011-09-18 10:09:56 EDT (Sun, 18 Sep 2011)
@@ -33,7 +33,7 @@
             else
             {
                 BOOST_ASSERT( factor <= 1000000l ); // doesn't handle large ticks
-                factor = 1000000l / factor;  // compute factor
+                factor = 1000000000l / factor;  // compute factor
                 if ( !factor ) factor = -1;
             }
         }
@@ -55,7 +55,7 @@
         if ( chrono_detail::tick_factor() != -1 )
         {
             return time_point(
-                    microseconds(c)*chrono_detail::tick_factor());
+                    nanoseconds(c*chrono_detail::tick_factor()));
         }
         else
         {
@@ -96,7 +96,7 @@
                 ec.clear();
             }
             return time_point(
-                    microseconds(c)*chrono_detail::tick_factor());
+                nanoseconds(c*chrono_detail::tick_factor()));
         }
         else
         {
@@ -148,7 +148,7 @@
                 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
         {
@@ -182,7 +182,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
         {
@@ -204,7 +204,7 @@
         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
         {
@@ -244,7 +244,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
         {
@@ -278,8 +278,8 @@
         if ( chrono_detail::tick_factor() != -1 )
         {
             time_point::rep r(
-                    c*chrono_detail::tick_factor(),
-                    (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
+                c*chrono_detail::tick_factor(),
+                (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
                     (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
             return time_point(duration(r));
         }
@@ -294,6 +294,7 @@
 process_cpu_clock::time_point process_cpu_clock::now( 
         system::error_code & ec ) 
 {
+
     tms tm;
     clock_t c = ::times( &tm );
     if ( c == clock_t(-1) ) // error
@@ -316,10 +317,10 @@
     {
         if ( chrono_detail::tick_factor() != -1 )
         {
-            time_point::rep r(
-                    c*chrono_detail::tick_factor(), 
-                    (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(), 
-                    (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
+          time_point::rep r(
+              c*chrono_detail::tick_factor(),
+              (tm.tms_utime + tm.tms_cutime)*chrono_detail::tick_factor(),
+                  (tm.tms_stime + tm.tms_cstime)*chrono_detail::tick_factor());
             return time_point(duration(r));
         }
         else
Modified: trunk/boost/chrono/process_cpu_clocks.hpp
==============================================================================
--- trunk/boost/chrono/process_cpu_clocks.hpp	(original)
+++ trunk/boost/chrono/process_cpu_clocks.hpp	2011-09-18 10:09:56 EDT (Sun, 18 Sep 2011)
@@ -74,6 +74,11 @@
                 : real(0)
                 , user(0)
                 , system(0){}
+            explicit process_cpu_clock_times(
+                process_real_cpu_clock::rep r)
+                : real(r)
+                , user(0)
+                , system(0){}
             process_cpu_clock_times(
                 process_real_cpu_clock::rep r,
                 process_user_cpu_clock::rep   u,
@@ -86,6 +91,10 @@
             process_user_cpu_clock::rep   user;    // user cpu time
             process_system_cpu_clock::rep system;  // system cpu time
 
+            operator process_real_cpu_clock::rep()
+            {
+              return real;
+            }
             bool operator==(process_cpu_clock_times const& rhs) {
                 return (real==rhs.real &&
                         user==rhs.user &&
Modified: trunk/boost/chrono/stopwatches/simple_stopwatch.hpp
==============================================================================
--- trunk/boost/chrono/stopwatches/simple_stopwatch.hpp	(original)
+++ trunk/boost/chrono/stopwatches/simple_stopwatch.hpp	2011-09-18 10:09:56 EDT (Sun, 18 Sep 2011)
@@ -11,6 +11,8 @@
 
 #include <boost/chrono/chrono.hpp>
 #include <boost/system/error_code.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
 
 namespace boost
 {
@@ -18,7 +20,7 @@
   {
 
     /**
-     * This class provides the simpler stopwath which is just able to give the elapsed time since its creation.
+     * This class provides the simpler stopwatch which is just able to give the elapsed time since its construction.
      */
     template<typename Clock=high_resolution_clock>
     class simple_stopwatch
@@ -32,7 +34,7 @@
       BOOST_CHRONO_STATIC_CONSTEXPR bool is_steady =             Clock::is_steady;
 
 
-      simple_stopwatch() :
+      simple_stopwatch() BOOST_CHRONO_NOEXCEPT :
         start_(clock::now())
       {
       }
@@ -50,7 +52,11 @@
         start_ = tmp;
       }
 
-      duration elapsed()
+      ~simple_stopwatch() BOOST_CHRONO_NOEXCEPT
+      {
+      }
+
+      duration elapsed() BOOST_CHRONO_NOEXCEPT
       {
         return clock::now() - start_;
       }
@@ -67,8 +73,28 @@
 
     private:
       time_point start_;
+      simple_stopwatch(const simple_stopwatch&); // = delete;
+      simple_stopwatch& operator=(const simple_stopwatch&); // = delete;
     };
 
+    typedef simple_stopwatch<system_clock> system_simple_stopwatch;
+#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
+    typedef simple_stopwatch<steady_clock> steady_simple_stopwatch;
+#endif
+    typedef simple_stopwatch<high_resolution_clock> high_resolution_simple_stopwatch;
+
+#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
+    typedef simple_stopwatch<process_user_cpu_clock> process_user_cpu_simple_stopwatch;
+    typedef simple_stopwatch<process_system_cpu_clock> process_system_cpu_simple_stopwatch;
+    typedef simple_stopwatch<process_real_cpu_clock> process_real_cpu_simple_stopwatch;
+    typedef simple_stopwatch<process_cpu_clock> process_cpu_simple_stopwatch;
+#endif
+
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+    typedef simple_stopwatch<thread_clock> thread_simple_stopwatch;
+#endif
+
+
   } // namespace chrono
 } // namespace boost
 
Modified: trunk/boost/chrono/system_clocks.hpp
==============================================================================
--- trunk/boost/chrono/system_clocks.hpp	(original)
+++ trunk/boost/chrono/system_clocks.hpp	2011-09-18 10:09:56 EDT (Sun, 18 Sep 2011)
@@ -127,8 +127,8 @@
       typedef chrono::time_point<system_clock>     time_point;
       BOOST_CHRONO_STATIC_CONSTEXPR bool is_steady =             false;
 
-      static BOOST_CHRONO_INLINE time_point  now() BOOST_CHRONO_NOEXCEPT;                         // throws on error
-      static BOOST_CHRONO_INLINE time_point  now(system::error_code & ec) ;  // never throws
+      static BOOST_CHRONO_INLINE time_point  now() BOOST_CHRONO_NOEXCEPT;
+      static BOOST_CHRONO_INLINE time_point  now(system::error_code & ec);
 
       static BOOST_CHRONO_INLINE std::time_t to_time_t(const time_point& t) BOOST_CHRONO_NOEXCEPT;
       static BOOST_CHRONO_INLINE time_point  from_time_t(std::time_t t) BOOST_CHRONO_NOEXCEPT;
@@ -151,8 +151,8 @@
       typedef chrono::time_point<steady_clock>  time_point;
       BOOST_CHRONO_STATIC_CONSTEXPR bool is_steady =             true;
 
-      static BOOST_CHRONO_INLINE time_point  now() BOOST_CHRONO_NOEXCEPT;                         // throws on error
-      static BOOST_CHRONO_INLINE time_point  now(system::error_code & ec) ;  // never throws
+      static BOOST_CHRONO_INLINE time_point  now() BOOST_CHRONO_NOEXCEPT;
+      static BOOST_CHRONO_INLINE time_point  now(system::error_code & ec);
   };
 #endif
 //----------------------------------------------------------------------------//
Modified: trunk/boost/chrono/thread_clock.hpp
==============================================================================
--- trunk/boost/chrono/thread_clock.hpp	(original)
+++ trunk/boost/chrono/thread_clock.hpp	2011-09-18 10:09:56 EDT (Sun, 18 Sep 2011)
@@ -10,6 +10,8 @@
 #ifndef BOOST_CHRONO_THREAD_CLOCK_HPP
 #define BOOST_CHRONO_THREAD_CLOCK_HPP
 
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+
 #include <boost/chrono/config.hpp>
 #include <boost/chrono/duration.hpp>
 #include <boost/chrono/time_point.hpp>
@@ -20,8 +22,6 @@
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 #endif
 
-#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
-
 namespace boost { namespace chrono {
 
 class BOOST_CHRONO_DECL thread_clock {
@@ -38,7 +38,6 @@
 } // namespace chrono
 } // namespace boost
 
-#endif
 
 #ifndef BOOST_CHRONO_HEADER_ONLY
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
@@ -46,4 +45,6 @@
 #include <boost/chrono/detail/inlined/thread_clock.hpp>
 #endif
 
+#endif
+
 #endif  // BOOST_CHRONO_THREAD_CLOCK_HPP