Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65289 - sandbox/chrono/boost/stopwatches
From: vicente.botet_at_[hidden]
Date: 2010-09-05 06:47:46


Author: viboes
Date: 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
New Revision: 65289
URL: http://svn.boost.org/trac/boost/changeset/65289

Log:
Suspendible clocks are now on Stopwatches lib

Added:
   sandbox/chrono/boost/stopwatches/scoped_suspend.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/suspendible_clock.hpp (contents, props changed)
Text files modified:
   sandbox/chrono/boost/stopwatches/stopclock.hpp | 5 +++--
   sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp | 5 +++--
   sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp | 4 ++--
   sandbox/chrono/boost/stopwatches/stopwatches.hpp | 9 ++++-----
   sandbox/chrono/boost/stopwatches/time_formatter.hpp | 1 -
   5 files changed, 12 insertions(+), 12 deletions(-)

Added: sandbox/chrono/boost/stopwatches/scoped_suspend.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/scoped_suspend.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -0,0 +1,40 @@
+// 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_STOPWATCHES_SCOPED_SUSPEND_CLOCK_HPP
+#define BOOST_STOPWATCHES_SCOPED_SUSPEND_CLOCK_HPP
+
+#include <boost/system/error_code.hpp>
+#include <boost/mpl/bool.hpp>
+
+namespace boost { namespace stopwatches {
+
+
+ template <class Clock>
+ struct is_suspendible : mpl:: false_ {};
+
+ template <class Clock>
+ class scoped_suspend {
+ public:
+ scoped_suspend(system::error_code & ec = system::throws) {
+ ec.clear();
+ }
+ ~scoped_suspend() {}
+ private:
+ //~ scoped_suspend(); // = delete;
+ scoped_suspend(const scoped_suspend&); // = delete;
+ scoped_suspend& operator=(const scoped_suspend&); // = delete;
+ };
+
+
+} // namespace stopwatches
+} // namespace boost
+
+
+#endif // BOOST_CHRONO_PROCESS_CPU_CLOCKS_HPP

Modified: sandbox/chrono/boost/stopwatches/stopclock.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopclock.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopclock.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -16,6 +16,7 @@
 #include <boost/stopwatches/stopwatch_formatter.hpp>
 #include <boost/stopwatches/time_formatter.hpp>
 #include <boost/stopwatches/stopwatch.hpp>
+#include <boost/stopwatches/suspendible_clock.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/type_traits/is_same.hpp>
 
@@ -64,12 +65,12 @@
     };
 
     template <>
- struct stopwatch_reporter_default_formatter<stopwatch<chrono::suspendible_clock<chrono::process_cpu_clock> > > {
+ struct stopwatch_reporter_default_formatter<stopwatch<stopwatches::suspendible_clock<chrono::process_cpu_clock> > > {
         typedef stopwatch_reporter_default_formatter<stopwatch<chrono::process_cpu_clock> >::type type;
     };
 
     template <>
- struct wstopwatch_reporter_default_formatter<stopwatch<chrono::suspendible_clock<chrono::process_cpu_clock> > > {
+ struct wstopwatch_reporter_default_formatter<stopwatch<stopwatches::suspendible_clock<chrono::process_cpu_clock> > > {
         typedef wstopwatch_reporter_default_formatter<stopwatch<chrono::process_cpu_clock> >::type type;
     };
 

Modified: sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -17,6 +17,7 @@
 #include <boost/stopwatches/stopwatch_accumulator.hpp>
 #include <boost/stopwatches/stopwatch_accumulator_formatter.hpp>
 #include <boost/stopwatches/stopwatch_accumulator_time_formatter.hpp>
+#include <boost/stopwatches/suspendible_clock.hpp>
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/type_traits/is_same.hpp>
@@ -66,12 +67,12 @@
     };
 
     template <typename Features, typename Weight>
- struct stopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::suspendible_clock<chrono::process_cpu_clock>, Features,Weight> > {
+ struct stopwatch_reporter_default_formatter<stopwatch_accumulator<stopwatches::suspendible_clock<chrono::process_cpu_clock>, Features,Weight> > {
         typedef stopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::process_cpu_clock> >::type type;
     };
 
     template <typename Features, typename Weight>
- struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::suspendible_clock<chrono::process_cpu_clock>, Features,Weight> > {
+ struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<stopwatches::suspendible_clock<chrono::process_cpu_clock>, Features,Weight> > {
         typedef wstopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::process_cpu_clock> >::type type;
     };
 

Modified: sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -23,7 +23,7 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/stopwatches/stopwatch_scoped.hpp>
 #include <boost/system/error_code.hpp>
-#include <boost/chrono/scoped_suspend.hpp>
+#include <boost/stopwatches/scoped_suspend.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
 #include <iostream>
@@ -175,7 +175,7 @@
 
     template <class Stopwatch, class Formatter>
     void basic_stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
- chrono::scoped_suspend<typename Stopwatch::clock> _(ec);
+ stopwatches::scoped_suspend<typename Stopwatch::clock> _(ec);
         if (ec) return;
         if ( m_format.empty() ) m_format = Formatter::default_format();
 

Modified: sandbox/chrono/boost/stopwatches/stopwatches.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopwatches.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopwatches.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -14,20 +14,19 @@
 #define BOOST_STOPWATCHES_STOPWATCHES_HPP
 
 //-----------------------------------------------------------------------------
-#include <boost/stopwatches/t24_hours.hpp>
-#include <boost/stopwatches/t24_hours_formatter.hpp>
-#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/stopwatches/scoped_stopclock.hpp>
 #include <boost/stopwatches/stopclock.hpp>
 #include <boost/stopwatches/stopclock_accumulator.hpp>
-#include <boost/stopwatches/scoped_stopclock.hpp>
 #include <boost/stopwatches/stopwatch.hpp>
 #include <boost/stopwatches/stopwatch_accumulator.hpp>
 #include <boost/stopwatches/stopwatch_accumulator_formatter.hpp>
+#include <boost/stopwatches/stopwatch_accumulator_time_formatter.hpp>
 #include <boost/stopwatches/stopwatch_formatter.hpp>
 #include <boost/stopwatches/stopwatch_reporter.hpp>
 #include <boost/stopwatches/stopwatch_scoped.hpp>
 #include <boost/stopwatches/time_formatter.hpp>
-#include <boost/stopwatches/stopwatch_accumulator_time_formatter.hpp>
+#include <boost/stopwatches/t24_hours.hpp>
+#include <boost/stopwatches/t24_hours_formatter.hpp>
 //-----------------------------------------------------------------------------
 
 #endif // BOOST_STOPWATCHES_STOPWATCHES_HPP

Added: sandbox/chrono/boost/stopwatches/suspendible_clock.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/suspendible_clock.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -0,0 +1,195 @@
+// 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_STOPWATCHES_SUSPENDIBLE_CLOCK_HPP
+#define BOOST_STOPWATCHES_SUSPENDIBLE_CLOCK_HPP
+
+#include <boost/version.hpp>
+#include <boost/chrono/chrono.hpp>
+#include <boost/stopwatches/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 stopwatches {
+
+ template < class Clock=chrono::high_resolution_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_;
+
+ thread_specific_context()
+ : suspended_(false)
+ , suspended_time_()
+ , suspended_duration_(duration::zero())
+ , suspend_level_(0)
+ {}
+ duration suspended(system::error_code & ec = system::throws) {
+ if (!suspended_) {
+ ec.clear();
+ return suspended_duration_;
+ } else {
+ time_point tmp;
+ tmp+=duration(Clock::now(ec).time_since_epoch());
+ 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());
+ if (ec) return;
+ ++suspend_level_;
+ suspended_time_ = tmp;
+ suspended_=true;
+ } else {
+ ec.clear();
+ ++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());
+ 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) {
+ 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) {
+#if (BOOST_VERSION / 100 % 1000) < 44
+ ec.assign( system::errc::resource_unavailable_try_again, system::generic_category );
+#else
+ ec.assign( system::errc::resource_unavailable_try_again, system::generic_category() );
+#endif
+ return 0;
+ }
+ try {
+ ptr_.reset(ptr);
+ } catch (...) {
+#if (BOOST_VERSION / 100 % 1000) < 44
+ ec.assign( system::errc::resource_unavailable_try_again, system::generic_category );
+#else
+ ec.assign( system::errc::resource_unavailable_try_again, system::generic_category() );
+#endif
+ return 0;
+ }
+ }
+ }
+ ec.clear();
+ return ptr;
+ }
+
+ static thread_specific_ptr<thread_specific_context> ptr_;
+ public:
+ static time_point now( ) {
+ time_point res;
+ res+= duration(Clock::now().time_since_epoch())-suspended();
+ return res;
+ }
+
+ static time_point now( system::error_code & ec ) {
+ time_point res;
+ typename Clock::time_point t=Clock::now(ec);
+ if (ec) return time_point();
+ res+= duration(t.time_since_epoch())-suspended(ec);
+ if (ec) return time_point();
+ 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))
+ {
+ if (ptr_!=0) ptr_->suspend(ec);
+ }
+ ~scoped_suspend() {
+ if (ptr_!=0) {
+ 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) : suspendible_clock<Clock>::scoped_suspend(ec) {}
+ private:
+ //~ scoped_suspend(); // = delete;
+ scoped_suspend(const scoped_suspend&); // = delete;
+ scoped_suspend& operator=(const scoped_suspend&); // = delete;
+ };
+
+} // namespace stopwatches
+} // namespace boost
+
+//~ #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_CHRONO_SUSPENDIBLE_CLOCK_HPP

Modified: sandbox/chrono/boost/stopwatches/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/time_formatter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/time_formatter.hpp 2010-09-05 06:47:44 EDT (Sun, 05 Sep 2010)
@@ -15,7 +15,6 @@
 #include <boost/current_function.hpp>
 #include <boost/stopwatches/detail/default_out.hpp>
 #include <boost/stopwatches/detail/adaptive_string.hpp>
-#include <boost/chrono/suspendible_clock.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>


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