|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63028 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-06-16 19:00:51
Author: viboes
Date: 2010-06-16 19:00:51 EDT (Wed, 16 Jun 2010)
New Revision: 63028
URL: http://svn.boost.org/trac/boost/changeset/63028
Log:
Add thread_clock for windows
Text files modified:
sandbox/chrono/boost/chrono/config.hpp | 11 +++++++-
sandbox/chrono/boost/chrono/thread_clock.hpp | 48 +++------------------------------------
2 files changed, 13 insertions(+), 46 deletions(-)
Modified: sandbox/chrono/boost/chrono/config.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/config.hpp (original)
+++ sandbox/chrono/boost/chrono/config.hpp 2010-06-16 19:00:51 EDT (Wed, 16 Jun 2010)
@@ -34,16 +34,19 @@
# if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32))
# define BOOST_CHRONO_WINDOWS_API
# define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+# define BOOST_CHRONO_HAS_THREAD_CLOCK
+# define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
# elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
# define BOOST_CHRONO_MAC_API
# define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+# define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
# else
# define BOOST_CHRONO_POSIX_API
# endif
# endif
# if defined( BOOST_CHRONO_POSIX_API )
-# include <time.h> //to check for CLOCK_REALTIME and CLOCK_MONOTONIC
+# include <time.h> //to check for CLOCK_REALTIME and CLOCK_MONOTONIC and _POSIX_THREAD_CPUTIME
# if defined(CLOCK_REALTIME)
# if defined(CLOCK_MONOTONIC)
# define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
@@ -51,6 +54,10 @@
# else
# error <time.h> does not supply CLOCK_REALTIME
# endif
+# if defined(_POSIX_THREAD_CPUTIME)
+# define BOOST_CHRONO_HAS_THREAD_CLOCK
+# define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC true
+# endif
# endif
@@ -83,7 +90,7 @@
// define constexpr related macros ------------------------------//
-#include <boost/chrono/config.hpp>
+//~ #include <boost/config.hpp>
#if defined(BOOST_NO_CONSTEXPR)
#define BOOST_CHRONO_CONSTEXPR
#define BOOST_CHRONO_CONST_REF const&
Modified: sandbox/chrono/boost/chrono/thread_clock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/thread_clock.hpp (original)
+++ sandbox/chrono/boost/chrono/thread_clock.hpp 2010-06-16 19:00:51 EDT (Wed, 16 Jun 2010)
@@ -10,9 +10,6 @@
#ifndef BOOST_CHRONO_THREAD_CLOCK_HPP
#define BOOST_CHRONO_THREAD_CLOCK_HPP
-#include <time.h>
-//#include <pthread.h>
-
#include <boost/chrono/config.hpp>
#include <boost/chrono/chrono.hpp>
#include <boost/system/error_code.hpp>
@@ -21,8 +18,7 @@
#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
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
namespace boost { namespace chrono {
@@ -32,46 +28,10 @@
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<thread_clock> time_point;
- static const bool is_monotonic = true;
+ static const bool is_monotonic = BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC;
- static time_point now( ) {
- // get the current thread
- pthread_t pth=pthread_self();
- // get the clock_id associated to the current thread
- clockid_t clock_id;
- pthread_getcpuclockid(pth, &clock_id);
- // get the timespec associated to the thread clock
- struct timespec ts;
- if ( ::clock_gettime( clock_id, &ts ) )
- {
- boost::throw_exception(
- system::system_error( errno, system::system_category, "chrono::thread_clock" ));
- }
-
- // transform to nanoseconds
- return time_point(duration(
- static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
-
- }
- static time_point now( system::error_code & ec ) {
- // get the current thread
- pthread_t pth=pthread_self();
- // get the clock_id associated to the current thread
- clockid_t clock_id;
- pthread_getcpuclockid(pth, &clock_id);
- // get the timespec associated to the thread clock
- struct timespec ts;
- if ( ::clock_gettime( clock_id, &ts ) )
- {
- ec.assign( errno, system::system_category );
- return time_point();
- }
- ec.clear();
- // transform to nanoseconds
- return time_point(duration(
- static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
-
- }
+ static time_point now( );
+ static time_point now( system::error_code & ec );
};
} // namespace chrono
} // namespace boost
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