Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63248 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-06-22 17:36:41


Author: viboes
Date: 2010-06-22 17:36:40 EDT (Tue, 22 Jun 2010)
New Revision: 63248
URL: http://svn.boost.org/trac/boost/changeset/63248

Log:
* error_code clear when succeeds
* remove default scoped_suspend deleted constructor
* cleanup suspendable_clock.hpp
Removed:
   sandbox/chrono/boost/chrono/suspendable_clock.hpp
Text files modified:
   sandbox/chrono/boost/chrono/scoped_suspend.hpp | 6 ++++--
   sandbox/chrono/boost/chrono/stopwatch.hpp | 5 +++++
   sandbox/chrono/boost/chrono/stopwatch_reporter.hpp | 16 ++--------------
   sandbox/chrono/boost/chrono/suspendible_clock.hpp | 19 ++++++++++++-------
   4 files changed, 23 insertions(+), 23 deletions(-)

Modified: sandbox/chrono/boost/chrono/scoped_suspend.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/scoped_suspend.hpp (original)
+++ sandbox/chrono/boost/chrono/scoped_suspend.hpp 2010-06-22 17:36:40 EDT (Tue, 22 Jun 2010)
@@ -22,10 +22,12 @@
     template <class Clock>
     class scoped_suspend {
     public:
- scoped_suspend(system::error_code & ec = system::throws) {}
+ scoped_suspend(system::error_code & ec = system::throws) {
+ ec.clear();
+ }
         ~scoped_suspend() {}
     private:
- scoped_suspend(); // = delete;
+ //~ scoped_suspend(); // = delete;
         scoped_suspend(const scoped_suspend&); // = delete;
         scoped_suspend& operator=(const scoped_suspend&); // = delete;
     };

Modified: sandbox/chrono/boost/chrono/stopwatch.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch.hpp 2010-06-22 17:36:40 EDT (Tue, 22 Jun 2010)
@@ -83,6 +83,7 @@
                 running_=true;
                 return start_;
             } else {
+ ec.clear();
                 return time_point();
             }
         }
@@ -97,6 +98,7 @@
                 running_=false;
                 return frozen;
             } else {
+ ec.clear();
                 return duration::zero();
             }
         }
@@ -128,6 +130,7 @@
                     suspended_=true;
                     return partial_;
                 } else {
+ ec.clear();
                     return duration::zero();
                 }
             } else {
@@ -142,6 +145,7 @@
                 suspended_=false;
                 return start_;
             } else {
+ ec.clear();
                 return time_point();
             }
         }
@@ -163,6 +167,7 @@
             start_ = time_point();
             level_=0;
             running_=false;
+ ec.clear();
         }
 
         typedef stopwatch_runner<stopwatch<Clock> > scoped_run;

Modified: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp 2010-06-22 17:36:40 EDT (Tue, 22 Jun 2010)
@@ -147,21 +147,9 @@
     void basic_stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
         chrono::scoped_suspend<typename Stopwatch::clock> _(ec);
         m_reported = true;
- if ( m_format.empty() ) m_format = Formatter::default_format();
-
- //typename Stopwatch::duration d = this->elapsed( ec );
- if ( &ec == &system::throws ) {
- Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec);
- } else {// non-throwing
- try {
- Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec );
- ec = system::error_code();
- } catch (...) { // eat any exceptions
- assert( 0 && "error reporting not fully implemented yet" );
- //ec = error_code( EIO, errno_ecat );
- }
- }
+ //~ if ( m_format.empty() ) m_format = Formatter::default_format();
 
+ Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec);
     }
 
 

Deleted: sandbox/chrono/boost/chrono/suspendable_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/suspendable_clock.hpp 2010-06-22 17:36:40 EDT (Tue, 22 Jun 2010)
+++ (empty file)
@@ -1,162 +0,0 @@
-// 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_SUSPENDIBLE_CLOCK_HPP
-#define BOOST_CHRONO_SUSPENDIBLE_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>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost { namespace chrono {
-
- template < class Clock >
- class suspendible_clock {
- public:
- typedef typename Clock::duration duration;
- typedef typename Clock::rep rep;
- typedef typename Clock::period period;
- typedef chrono::time_point<suspendible_clock<Clock> > time_point;
- static const bool is_monotonic = true;
-
- private:
- struct thread_specific_context {
- bool suspended_;
- time_point suspended_time_;
- 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;
- tmp+=duration(Clock::now(ec).time_since_epoch().count());
- if (ec) return;
- ++suspend_level_;
- suspended_time_ = tmp;
- suspended_=true;
- } else {
- ++suspend_level_;
- }
- }
- void resume( system::error_code & ec = system::throws ) {
- if (suspended_&&(--suspend_level_==0)) {
- time_point tmp;
- tmp+=duration(Clock::now(ec).time_since_epoch().count());
- if (ec) return;
- suspended_duration_ += tmp - suspended_time_;
- suspended_=false;
- }
- }
-
- };
- static thread_specific_context* instance(system::error_code & ec) {
- thread_specific_context* ptr= ptr_.get();
- if (ptr==0) {
- if (ec == system::throws) {
- std::auto_ptr<thread_specific_context> ptr2(new thread_specific_context());
- ptr_.reset(ptr2.get());
- ptr = ptr2.release();
- } else {
- ptr=(new(std::nothrow) thread_specific_context());
- if (ptr==0) {
- //ec=...
- return 0;
- }
- try {
- ptr_.reset(ptr);
- } catch (...) {
- //ec=...
- return 0;
- }
- }
- }
- return ptr;
- }
-
- static thread_specific_ptr<thread_specific_context> ptr_;
- public:
- static time_point now( system::error_code & ec = system::throws ) {
- 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);
- }
- 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)
- : ptr_(instance(ec))
- {
- ptr_->suspend(ec);
- }
- ~scoped_suspend() {
- system::error_code ec;
- ptr_->resume(ec);
- }
- private:
- thread_specific_context* ptr_;
- scoped_suspend(); // = delete;
- scoped_suspend(const scoped_suspend&); // = delete;
- scoped_suspend& operator=(const scoped_suspend&); // = delete;
- };
-
- };
-
- template < class Clock >
- thread_specific_ptr<typename suspendible_clock<Clock>::thread_specific_context> suspendible_clock<Clock>::ptr_;
-
-
-
- template <class Clock>
- struct is_suspendible<suspendible_clock<Clock> > : mpl:: true_ {};
-
-
-
- template <class Clock>
- class scoped_suspend<suspendible_clock<Clock> >
- : public suspendible_clock<Clock>::scoped_suspend {
- public:
- scoped_suspend(system::error_code & ec = system::throws) : Clock::scoped_suspend(ec) {}
- };
-
-} // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP

Modified: sandbox/chrono/boost/chrono/suspendible_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/suspendible_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/suspendible_clock.hpp 2010-06-22 17:36:40 EDT (Tue, 22 Jun 2010)
@@ -11,7 +11,7 @@
 #define BOOST_CHRONO_SUSPENDIBLE_CLOCK_HPP
 
 #include <boost/chrono/chrono.hpp>
-#include <boost/chrono/scoped_suspend.hpp>
+//~ #include <boost/chrono/scoped_suspend.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/thread/tss.hpp>
 #include <memory>
@@ -44,6 +44,7 @@
             {}
             duration suspended(system::error_code & ec = system::throws) {
                 if (!suspended_) {
+ ec.clear();
                     return suspended_duration_;
                 } else {
                     time_point tmp;
@@ -62,6 +63,7 @@
                     suspended_time_ = tmp;
                     suspended_=true;
                 } else {
+ ec.clear();
                     ++suspend_level_;
                 }
             }
@@ -72,31 +74,34 @@
                     if (ec) return;
                     suspended_duration_ += tmp - suspended_time_;
                     suspended_=false;
- }
+ } else {
+ ec.clear();
+ }
             }
 
         };
         static thread_specific_context* instance(system::error_code & ec) {
             thread_specific_context* ptr= ptr_.get();
             if (ptr==0) {
- if (ec == system::throws) {
+ if (&ec == &system::throws) {
                     std::auto_ptr<thread_specific_context> ptr2(new thread_specific_context());
                     ptr_.reset(ptr2.get());
                     ptr = ptr2.release();
                 } else {
                     ptr=(new(std::nothrow) thread_specific_context());
                     if (ptr==0) {
- //ec=...
+ ec.assign( system::errc::resource_unavailable_try_again, system::generic_category );
                         return 0;
                     }
                     try {
                         ptr_.reset(ptr);
                     } catch (...) {
- //ec=...
+ ec.assign( system::errc::resource_unavailable_try_again, system::generic_category );
                         return 0;
                     }
                 }
             }
+ ec.clear();
             return ptr;
         }
 
@@ -149,7 +154,7 @@
             }
         private:
             thread_specific_context* ptr_;
- scoped_suspend(); // = delete;
+ //~ scoped_suspend(); // = delete;
             scoped_suspend(const scoped_suspend&); // = delete;
             scoped_suspend& operator=(const scoped_suspend&); // = delete;
         };
@@ -168,7 +173,7 @@
     public:
         scoped_suspend(system::error_code & ec = system::throws) : suspendible_clock<Clock>::scoped_suspend(ec) {}
     private:
- scoped_suspend(); // = delete;
+ //~ scoped_suspend(); // = delete;
         scoped_suspend(const scoped_suspend&); // = delete;
         scoped_suspend& operator=(const scoped_suspend&); // = delete;
     };


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