Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63029 - in sandbox/chrono/libs/chrono: build src src/mac src/posix src/win test
From: vicente.botet_at_[hidden]
Date: 2010-06-16 19:06:26


Author: viboes
Date: 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
New Revision: 63029
URL: http://svn.boost.org/trac/boost/changeset/63029

Log:
Add thread_clock for windows
Added:
   sandbox/chrono/libs/chrono/src/mac/thread_clock.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/src/posix/thread_clock.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/src/thread_clock.cpp (contents, props changed)
   sandbox/chrono/libs/chrono/src/win/thread_clock.cpp (contents, props changed)
Text files modified:
   sandbox/chrono/libs/chrono/build/Jamfile.v2 | 2 +-
   sandbox/chrono/libs/chrono/src/win/process_clock.cpp | 6 +++---
   sandbox/chrono/libs/chrono/test/Jamfile.v2 | 2 +-
   sandbox/chrono/libs/chrono/test/clock_name.hpp | 1 +
   4 files changed, 6 insertions(+), 5 deletions(-)

Modified: sandbox/chrono/libs/chrono/build/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/build/Jamfile.v2 (original)
+++ sandbox/chrono/libs/chrono/build/Jamfile.v2 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -45,7 +45,7 @@
         <link>static:<define>BOOST_CHRONO_STATIC_LINK=1
     ;
 
-SOURCES = chrono process_clock run_timer run_timer_static process_cpu_clocks ;
+SOURCES = chrono process_clock thread_clock run_timer run_timer_static process_cpu_clocks ;
 
 lib boost_chrono
     : $(SOURCES).cpp

Added: sandbox/chrono/libs/chrono/src/mac/thread_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/src/mac/thread_clock.cpp 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,19 @@
+// boost thread_clock.cpp -----------------------------------------------------------//
+
+// Copyright Vicente J. Botet Escriba 2010
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+//--------------------------------------------------------------------------------------//
+
+// define BOOST_CHRONO_SOURCE so that <boost/chrono/config.hpp> knows
+// the library is being built (possibly exporting rather than importing code)
+#define BOOST_CHRONO_SOURCE
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <cassert>
+

Added: sandbox/chrono/libs/chrono/src/posix/thread_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/src/posix/thread_clock.cpp 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,64 @@
+// boost thread_clock.cpp -----------------------------------------------------------//
+
+// Copyright Beman Dawes 1994, 2006, 2008
+// Copyright Vicente J. Botet Escriba 2009
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+//--------------------------------------------------------------------------------------//
+
+// define BOOST_CHRONO_SOURCE so that <boost/chrono/config.hpp> knows
+// the library is being built (possibly exporting rather than importing code)
+#define BOOST_CHRONO_SOURCE
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <cassert>
+
+# include <sys/times.h>
+# include <unistd.h>
+
+namespace boost { namespace chrono {
+
+ thread_clock::time_point thread_clock::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));
+
+ }
+ thread_clock::time_point thread_clock::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));
+
+ }
+} }

Added: sandbox/chrono/libs/chrono/src/thread_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/src/thread_clock.cpp 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,43 @@
+// boost thread_clock.cpp -----------------------------------------------------------//
+
+// Copyright 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/chrono for documentation.
+
+//--------------------------------------------------------------------------------------//
+
+
+// define BOOST_CHRONO_SOURCE so that <boost/chrono/config.hpp> knows
+// the library is being built (possibly exporting rather than importing code)
+#define BOOST_CHRONO_SOURCE
+
+#include <boost/chrono/config.hpp>
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+#include <boost/chrono/thread_clock.hpp>
+#include <cassert>
+
+//----------------------------------------------------------------------------//
+// Windows //
+//----------------------------------------------------------------------------//
+#if defined(BOOST_CHRONO_WINDOWS_API)
+#include "win/thread_clock.cpp"
+
+//----------------------------------------------------------------------------//
+// Mac //
+//----------------------------------------------------------------------------//
+#elif defined(BOOST_CHRONO_MAC_API)
+#include "mac/thread_clock.cpp"
+
+//----------------------------------------------------------------------------//
+// POSIX //
+//----------------------------------------------------------------------------//
+#elif defined(BOOST_CHRONO_POSIX_API)
+#include "posix/thread_clock.cpp"
+
+#endif // POSIX
+
+
+#endif

Modified: sandbox/chrono/libs/chrono/src/win/process_clock.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/src/win/process_clock.cpp (original)
+++ sandbox/chrono/libs/chrono/src/win/process_clock.cpp 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -46,9 +46,9 @@
       }
       else
       {
- assert( 0 && "error handling not implemented yet" );
- //ec = error_code( ::GetLastError(), native_ecat );
- //times_.real = times_.system = times_.user = nanoseconds(-1);
+ //~ assert( 0 && "error handling not implemented yet" );
+ ec.assign( ::GetLastError(), system::system_category );
+ times_.real = times_.system = times_.user = nanoseconds(-1);
       }
 
     }

Added: sandbox/chrono/libs/chrono/src/win/thread_clock.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/src/win/thread_clock.cpp 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -0,0 +1,90 @@
+// boost thread_clock.cpp -----------------------------------------------------------//
+
+// Copyright 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/chrono for documentation.
+
+//--------------------------------------------------------------------------------------//
+
+// define BOOST_CHRONO_SOURCE so that <boost/chrono/config.hpp> knows
+// the library is being built (possibly exporting rather than importing code)
+#define BOOST_CHRONO_SOURCE
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/thread_clock.hpp>
+#include <cassert>
+
+# include <windows.h>
+
+namespace boost
+{
+ namespace chrono
+ {
+
+ thread_clock::time_point thread_clock::now( system::error_code & ec )
+ {
+
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ FILETIME creation, exit, user_time, system_time;
+
+ if ( ::GetThreadTimes( ::GetCurrentThread (), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ duration user = duration(
+ ((static_cast<duration::rep>(user_time.dwHighDateTime) << 32)
+ | user_time.dwLowDateTime) * 100 );
+
+ duration system = duration(
+ ((static_cast<duration::rep>(system_time.dwHighDateTime) << 32)
+ | system_time.dwLowDateTime) * 100 );
+
+ ec.clear();
+ return time_point(system+user);
+
+ }
+ else
+ {
+ //~ assert( 0 && "error handling not implemented yet" );
+ ec.assign( ::GetLastError(), system::system_category );
+ return thread_clock::time_point(duration(0));
+ }
+
+ }
+
+
+ thread_clock::time_point thread_clock::now( )
+ {
+
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ FILETIME creation, exit, user_time, system_time;
+
+ if ( ::GetThreadTimes( ::GetCurrentThread (), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ duration user = duration(
+ ((static_cast<duration::rep>(user_time.dwHighDateTime) << 32)
+ | user_time.dwLowDateTime) * 100 );
+
+ duration system = duration(
+ ((static_cast<duration::rep>(system_time.dwHighDateTime) << 32)
+ | system_time.dwLowDateTime) * 100 );
+
+ return time_point(system+user);
+
+ }
+ else
+ {
+ DWORD cause = ::GetLastError();
+ boost::throw_exception(
+ system::system_error( ::GetLastError(), system::system_category, "chrono::monotonic_clock" ));
+ }
+
+ }
+
+
+
+ } // namespace chrono
+} // namespace boost

Modified: sandbox/chrono/libs/chrono/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/test/Jamfile.v2 (original)
+++ sandbox/chrono/libs/chrono/test/Jamfile.v2 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -20,7 +20,7 @@
     : requirements
         <os>LINUX:<threading>multi
         #<library>/boost/chrono//boost_chrono
- #<library>/boost/system//boost_system
+ <library>/boost/system//boost_system
         <library>../build//boost_chrono
         #<library>/boost/thread//boost_thread/<link>shared
         # uncomment the line above if you build outside the Boost release

Modified: sandbox/chrono/libs/chrono/test/clock_name.hpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock_name.hpp (original)
+++ sandbox/chrono/libs/chrono/test/clock_name.hpp 2010-06-16 19:06:25 EDT (Wed, 16 Jun 2010)
@@ -1,6 +1,7 @@
 // stopclock_perf.cpp ---------------------------------------------------//
 
 // Copyright 2009 Vicente J. Botet Escriba
+// Copyright 2009 Howard Hinnant
 
 // Distributed under the Boost Software License, Version 1.0.
 // See http://www.boost.org/LICENSE_1_0.txt


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