Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59266 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-01-25 15:10:31


Author: viboes
Date: 2010-01-25 15:10:30 EST (Mon, 25 Jan 2010)
New Revision: 59266
URL: http://svn.boost.org/trac/boost/changeset/59266

Log:
Boost.Chrono: Version 0.3.2,
* bug fixes on suspendible_clock
* Added BOOST_CHRONO_HAS_THREAD_CLOCK macro when thread_clock is defined + compile issue fixed
Text files modified:
   sandbox/chrono/boost/chrono/suspendible_clock.hpp | 39 +++++++++++++++++++++++++++++----------
   sandbox/chrono/boost/chrono/thread_clock.hpp | 13 ++++++++-----
   2 files changed, 37 insertions(+), 15 deletions(-)

Modified: sandbox/chrono/boost/chrono/suspendible_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/suspendible_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/suspendible_clock.hpp 2010-01-25 15:10:30 EST (Mon, 25 Jan 2010)
@@ -36,11 +36,18 @@
             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_) return suspended_duration_;
- else {
+ if (!suspended_) {
+ return suspended_duration_;
+ } else {
                     time_point tmp;
- tmp+=duration(Clock::now(ec).time_since_epoch().count());
+ tmp+=duration(Clock::now(ec).time_since_epoch());
                     if (ec) return duration::zero();
                     return suspended_duration_ + tmp - suspended_time_;
                 }
@@ -49,7 +56,7 @@
             void suspend( system::error_code & ec = system::throws ) {
                 if (!suspended_) {
                     time_point tmp;
- tmp+=duration(Clock::now(ec).time_since_epoch().count());
+ tmp+=duration(Clock::now(ec).time_since_epoch());
                     if (ec) return;
                     ++suspend_level_;
                     suspended_time_ = tmp;
@@ -61,7 +68,7 @@
             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());
+ tmp+=duration(Clock::now(ec).time_since_epoch());
                     if (ec) return;
                     suspended_duration_ += tmp - suspended_time_;
                     suspended_=false;
@@ -95,9 +102,18 @@
 
         static thread_specific_ptr<thread_specific_context> ptr_;
     public:
- static time_point now( system::error_code & ec = system::throws ) {
+ static time_point now( ) {
             time_point res;
- res+= duration(Clock::now(ec).time_since_epoch().count())-suspended(ec);
+ 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;
         }
 
@@ -122,11 +138,14 @@
             scoped_suspend(system::error_code & ec = system::throws)
                 : ptr_(instance(ec))
             {
- ptr_->suspend(ec);
+ if (ptr_!=0) ptr_->suspend(ec);
             }
             ~scoped_suspend() {
- system::error_code ec;
- ptr_->resume(ec);
+ if (ptr_!=0) {
+ system::error_code ec;
+ ptr_->resume(ec);
+ }
+
             }
         private:
             thread_specific_context* ptr_;

Modified: sandbox/chrono/boost/chrono/thread_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/thread_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/thread_clock.hpp 2010-01-25 15:10:30 EST (Mon, 25 Jan 2010)
@@ -11,7 +11,7 @@
 #define BOOST_CHRONO_THREAD_CLOCK_HPP
 
 #include <time.h>
-#include <pthread.h>
+//#include <pthread.h>
 
 #include <boost/chrono/config.hpp>
 #include <boost/chrono/chrono.hpp>
@@ -21,9 +21,11 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+#if defined(BOOST_CHRONO_POSIX_API) && defined(_POSIX_THREAD_CPUTIME)
+#define BOOST_CHRONO_HAS_THREAD_CLOCK
+
 namespace boost { namespace chrono {
 
-#if defined(BOOST_CHRONO_POSIX_API) && defined(_POSIX_THREAD_CPUTIME)
 class BOOST_CHRONO_DECL thread_clock {
 public:
     typedef nanoseconds duration;
@@ -37,7 +39,7 @@
         pthread_t pth=pthread_self();
         // get the clock_id associated to the current thread
         clockid_t clock_id;
- pthread_getcpuclockid(pth, clock_id);
+ pthread_getcpuclockid(pth, &clock_id);
         // get the timespec associated to the thread clock
         struct timespec ts;
         if ( ::clock_gettime( clock_id, &ts ) )
@@ -56,7 +58,7 @@
         pthread_t pth=pthread_self();
         // get the clock_id associated to the current thread
         clockid_t clock_id;
- pthread_getcpuclockid(pth, clock_id);
+ pthread_getcpuclockid(pth, &clock_id);
         // get the timespec associated to the thread clock
         struct timespec ts;
         if ( ::clock_gettime( clock_id, &ts ) )
@@ -71,10 +73,11 @@
              
     }
 };
-#endif
 } // namespace chrono
 } // namespace boost
 
+#endif
+
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
 #endif // BOOST_CHRONO_THREAD_CLOCK_HPP


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