Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59211 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-01-21 18:24:57


Author: viboes
Date: 2010-01-21 18:24:57 EST (Thu, 21 Jan 2010)
New Revision: 59211
URL: http://svn.boost.org/trac/boost/changeset/59211

Log:
Boost.Chrono: Version 0.3.2,
* added scoped_suspend.hpp to avoid deep dependencies with suspendable_clock.hpp
* More correction with duration(0)
* Correction on suspendable_clock.hpp after testing
Added:
   sandbox/chrono/boost/chrono/scoped_suspend.hpp (contents, props changed)
Text files modified:
   sandbox/chrono/boost/chrono/stopwatch.hpp | 23 +++++++-----------
   sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp | 21 +++++++---------
   sandbox/chrono/boost/chrono/stopwatch_reporter.hpp | 2
   sandbox/chrono/boost/chrono/suspendable_clock.hpp | 49 +++++++++++++++++++++++++--------------
   4 files changed, 50 insertions(+), 45 deletions(-)

Added: sandbox/chrono/boost/chrono/scoped_suspend.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/scoped_suspend.hpp 2010-01-21 18:24:57 EST (Thu, 21 Jan 2010)
@@ -0,0 +1,34 @@
+// boost/chrono/process_cpu_clocks.hpp -----------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_SCOPED_SUSPEND_CLOCK_HPP
+#define BOOST_CHRONO_SCOPED_SUSPEND_CLOCK_HPP
+
+#include <boost/system/error_code.hpp>
+#include <boost/mpl/bool.hpp>
+
+namespace boost { namespace chrono {
+
+
+ template <class Clock>
+ struct is_suspendable : mpl:: false_ {};
+
+ template <class Clock>
+ class scoped_suspend {
+ public:
+ scoped_suspend(system::error_code & ec = system::throws) {}
+ ~scoped_suspend() {}
+ };
+
+
+} // namespace chrono
+} // namespace boost
+
+
+#endif // BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP

Modified: sandbox/chrono/boost/chrono/stopwatch.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch.hpp 2010-01-21 18:24:57 EST (Thu, 21 Jan 2010)
@@ -62,17 +62,12 @@
         explicit stopwatch( system::error_code & ec = system::throws )
         : running_(false), suspended_(false), start_(), level_(0), partial_(duration::zero()), suspend_level_(0)
         {
- //duration d0((0));
- //partial_=d0;
             start(ec);
         }
 
         explicit stopwatch( const dont_start_t& t )
         : running_(false), suspended_(false), start_(), level_(0), partial_(duration::zero()), suspend_level_(0)
- {
- //duration d0((0));
- //partial_=d0;
- }
+ { }
 
         time_point start( system::error_code & ec = system::throws ) {
             ++level_;
@@ -90,14 +85,14 @@
         duration stop( system::error_code & ec = system::throws ) {
             if (running_&&(--level_==0)) {
                 time_point tmp=clock::now( ec );
- if (ec) return duration(0);
+ if (ec) return duration::zero();
                 partial_ += tmp - start_;
                 duration frozen= partial_;
- partial_=duration(0);
+ partial_=duration::zero();
                 running_=false;
                 return frozen;
             } else {
- return duration(0);
+ return duration::zero();
             }
         }
 
@@ -108,9 +103,9 @@
             if (running_&&(--level_==0)) {
                 partial_ += tmp - start_;
                 frozen = partial_;
- partial_=duration(0);
+ partial_=duration::zero();
             } else {
- frozen = duration(0);
+ frozen = duration::zero();
                 running_=true;
             }
             start_=tmp;
@@ -123,15 +118,15 @@
                 ++suspend_level_;
                 if (!suspended_) {
                     time_point tmp=clock::now( ec );
- if (ec) return duration(0);
+ if (ec) return duration::zero();
                     partial_ += tmp - start_;
                     suspended_=true;
                     return partial_;
                 } else {
- return duration(0);
+ return duration::zero();
                 }
             } else {
- return duration(0);
+ return duration::zero();
             }
         }
         time_point resume( system::error_code & ec = system::throws ) {

Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp 2010-01-21 18:24:57 EST (Thu, 21 Jan 2010)
@@ -76,10 +76,7 @@
         stopwatch_accumulator( )
         : running_(false), suspended_(false), accumulated_(),
           partial_(), start_(duration::zero()), level_(0), suspend_level_(0)
- {
- //duration d0((0));
- //partial_=d0;
- }
+ {}
 
         std::pair<duration, time_point> restart( system::error_code & ec = system::throws ) {
             time_point tmp=clock::now( ec );
@@ -87,7 +84,7 @@
             if (running_&&(--level_==0)) {
                 partial_ += tmp - start_;
                 accumulated_(partial_.count());
- partial_=duration(0);
+ partial_=duration::zero();
             } else {
                 running_=true;
             }
@@ -112,14 +109,14 @@
         duration stop( system::error_code & ec = system::throws ) {
             if (running_&&(--level_==0)) {
                 time_point tmp=clock::now( ec );
- if (ec) return duration(0);
+ if (ec) return duration::zero();
                 partial_ += tmp - start_;
                 accumulated_(partial_.count());
- partial_=duration(0);
+ partial_=duration::zero();
                 running_=false;
                 return duration(accumulators::extract::sum(accumulated_));
             } else {
- return duration(0);
+ return duration::zero();
             }
         }
 
@@ -128,15 +125,15 @@
                 ++suspend_level_;
                 if (!suspended_) {
                     time_point tmp=clock::now( ec );
- if (ec) return duration(0);
+ if (ec) return duration::zero();
                     partial_ += tmp - start_;
                     suspended_=true;
                     return duration(accumulators::sum(accumulated_));
                 } else {
- return duration(0);
+ return duration::zero();
                 }
             } else {
- return duration(0);
+ return duration::zero();
             }
         }
         time_point resume( system::error_code & ec = system::throws ) {
@@ -157,7 +154,7 @@
                     return duration(accumulators::sum(accumulated_));
                 else {
                     time_point tmp = clock::now( ec );
- if (ec) return duration(0);
+ if (ec) return duration::zero();
                     return duration(accumulators::sum(accumulated_))+tmp - start_;
                 }
             } else {

Modified: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp 2010-01-21 18:24:57 EST (Thu, 21 Jan 2010)
@@ -13,7 +13,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/stopwatch_scoped.hpp>
 #include <boost/system/error_code.hpp>
-#include <boost/chrono/suspendable_clock.hpp>
+#include <boost/chrono/scoped_suspend.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
 #include <iostream>

Modified: sandbox/chrono/boost/chrono/suspendable_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/suspendable_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/suspendable_clock.hpp 2010-01-21 18:24:57 EST (Thu, 21 Jan 2010)
@@ -11,6 +11,7 @@
 #define BOOST_CHRONO_SUSPENDABLE_CLOCK_HPP
 
 #include <boost/chrono/chrono.hpp>
+#include <boost/chrono/scoped_suspend.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/thread/tss.hpp>
 #include <memory>
@@ -35,9 +36,20 @@
             duration suspended_duration_;
             std::size_t suspend_level_;
             
+ duration suspended(system::error_code & ec = system::throws) {
+ if (!suspended_) return suspended_duration_;
+ else {
+ time_point tmp;
+ tmp+=duration(Clock::now(ec).time_since_epoch().count());
+ if (ec) return duration::zero();
+ return suspended_duration_ + tmp - suspended_time_;
+ }
+ }
+
             void suspend( system::error_code & ec = system::throws ) {
                 if (!suspended_) {
- time_point tmp=Clock::now( ec );
+ time_point tmp;
+ tmp+=duration(Clock::now(ec).time_since_epoch().count());
                     if (ec) return;
                     ++suspend_level_;
                     suspended_time_ = tmp;
@@ -48,7 +60,8 @@
             }
             void resume( system::error_code & ec = system::throws ) {
                 if (suspended_&&(--suspend_level_==0)) {
- time_point tmp = Clock::now( ec );
+ time_point tmp;
+ tmp+=duration(Clock::now(ec).time_since_epoch().count());
                     if (ec) return;
                     suspended_duration_ += tmp - suspended_time_;
                     suspended_=false;
@@ -79,27 +92,31 @@
             }
             return ptr;
         }
- duration suspended(system::error_code & ec = system::throws)
- {
- thread_specific_context* ptr= instance(ec);
- if (ptr!=0) return ptr->suspended_duration_;
- else return duration(0);
- }
 
         static thread_specific_ptr<thread_specific_context> ptr_;
     public:
         static time_point now( system::error_code & ec = system::throws ) {
- return Clock::now(ec)-suspended(ec);
+ time_point res;
+ res+= duration(Clock::now(ec).time_since_epoch().count())-suspended(ec);
+ return res;
         }
 
         static void suspend( system::error_code & ec = system::throws ) {
             thread_specific_context* ptr= instance(ec);
             if (ptr!=0) ptr->suspend(ec);
         }
- void resume( system::error_code & ec = system::throws ) {
+ static void resume( system::error_code & ec = system::throws ) {
             thread_specific_context* ptr= instance(ec);
             if (ptr!=0) ptr->resume(ec);
         }
+ static duration suspended(system::error_code & ec = system::throws)
+ {
+ thread_specific_context* ptr= instance(ec);
+ if (ptr!=0) {
+ return ptr->suspended(ec);
+ }
+ else return duration::zero();
+ }
         class scoped_suspend {
         public:
             scoped_suspend(system::error_code & ec = system::throws)
@@ -119,19 +136,15 @@
     
     };
 
- template <class Clock>
- struct is_suspendable : mpl:: false_ {};
+ template < class Clock >
+ thread_specific_ptr<typename suspendable_clock<Clock>::thread_specific_context> suspendable_clock<Clock>::ptr_;
+
+
         
     template <class Clock>
     struct is_suspendable<suspendable_clock<Clock> > : mpl:: true_ {};
         
         
- template <class Clock>
- class scoped_suspend {
- public:
- scoped_suspend(system::error_code & ec = system::throws) {}
- ~scoped_suspend() {}
- };
 
     template <class Clock>
     class scoped_suspend<suspendable_clock<Clock> >


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