|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74835 - branches/release/boost/chrono/detail/inlined/win
From: vicente.botet_at_[hidden]
Date: 2011-10-08 21:10:03
Author: viboes
Date: 2011-10-08 21:10:03 EDT (Sat, 08 Oct 2011)
New Revision: 74835
URL: http://svn.boost.org/trac/boost/changeset/74835
Log:
Chrono:Fix bad merge
Text files modified:
branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp | 281 ++++++++++++++++++++++++++++++++++++---
1 files changed, 255 insertions(+), 26 deletions(-)
Modified: branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp
==============================================================================
--- branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp (original)
+++ branches/release/boost/chrono/detail/inlined/win/process_cpu_clocks.hpp 2011-10-08 21:10:03 EDT (Sat, 08 Oct 2011)
@@ -1,5 +1,6 @@
-// boost process_cpu_clocks.cpp -----------------------------------------------------------//
+// boost process_timer.cpp -----------------------------------------------------------//
+// Copyright Beman Dawes 1994, 2006, 2008
// Copyright 2009-2010 Vicente J. Botet Escriba
// Distributed under the Boost Software License, Version 1.0.
@@ -8,38 +9,266 @@
// See http://www.boost.org/libs/chrono for documentation.
//--------------------------------------------------------------------------------------//
-#ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CPU_CLOCKS_HPP
-#define BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CPU_CLOCKS_HPP
+#ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CLOCK_HPP
+#define BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CLOCK_HPP
#include <boost/chrono/config.hpp>
+//#include <boost/chrono/system_clocks.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <cassert>
+#include <time.h>
+
+#include <boost/detail/win/GetLastError.hpp>
+#include <boost/detail/win/GetCurrentProcess.hpp>
+#include <boost/detail/win/GetProcessTimes.hpp>
+
+namespace boost
+{
+namespace chrono
+{
+
+process_real_cpu_clock::time_point process_real_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
+{
+ clock_t c = ::clock();
+ if ( c == clock_t(-1) ) // error
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ }
+ return time_point(
+ duration(c*(1000000000l/CLOCKS_PER_SEC))
+ );
+}
+
+#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
+process_real_cpu_clock::time_point process_real_cpu_clock::now(
+ system::error_code & ec)
+{
+ clock_t c = ::clock();
+ if ( c == clock_t(-1) ) // error
+ {
+ boost::throw_exception(
+ system::system_error(
+ errno,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
+ "chrono::process_real_cpu_clock" ));
+ }
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(
+ duration(c*(1000000000l/CLOCKS_PER_SEC))
+ );
+}
+#endif
-#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
+process_user_cpu_clock::time_point process_user_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
+{
-#include <boost/version.hpp>
-#include <boost/chrono/process_cpu_clocks.hpp>
-#include <boost/throw_exception.hpp>
-#include <boost/system/system_error.hpp>
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
+
+ if ( boost::detail::win32::GetProcessTimes(
+ boost::detail::win32::GetCurrentProcess(), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ return time_point(duration(
+ ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
+ | user_time.dwLowDateTime) * 100
+ ));
+ }
+ else
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ return time_point();
+ }
+
+}
+
+#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
+process_user_cpu_clock::time_point process_user_cpu_clock::now(
+ system::error_code & ec)
+{
+
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
+
+ if ( boost::detail::win32::GetProcessTimes(
+ boost::detail::win32::GetCurrentProcess(), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(duration(
+ ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
+ | user_time.dwLowDateTime) * 100
+ ));
+ }
+ else
+ {
+ boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(
+ system::system_error(
+ cause,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
+ "chrono::process_user_cpu_clock" ));
+ }
+ else
+ {
+ ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
+ return time_point();
+ }
+ }
+
+}
+#endif
+
+process_system_cpu_clock::time_point process_system_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
+{
+
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
+
+ if ( boost::detail::win32::GetProcessTimes(
+ boost::detail::win32::GetCurrentProcess(), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ return time_point(duration(
+ ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
+ | system_time.dwLowDateTime) * 100
+ ));
+ }
+ else
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ return time_point();
+ }
+
+}
+
+#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
+process_system_cpu_clock::time_point process_system_cpu_clock::now(
+ system::error_code & ec)
+{
+
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
+
+ if ( boost::detail::win32::GetProcessTimes(
+ boost::detail::win32::GetCurrentProcess(), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ return time_point(duration(
+ ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
+ | system_time.dwLowDateTime) * 100
+ ));
+ }
+ else
+ {
+ boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(
+ system::system_error(
+ cause,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
+ "chrono::process_system_cpu_clock" ));
+ }
+ else
+ {
+ ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
+ return time_point();
+ }
+ }
+
+}
+#endif
+
+process_cpu_clock::time_point process_cpu_clock::now() BOOST_CHRONO_NOEXCEPT
+{
-//----------------------------------------------------------------------------//
-// Windows //
-//----------------------------------------------------------------------------//
-#if defined(BOOST_CHRONO_WINDOWS_API)
-#include <boost/chrono/detail/inlined/win/process_cpu_clocks.hpp>
-
-//----------------------------------------------------------------------------//
-// Mac //
-//----------------------------------------------------------------------------//
-#elif defined(BOOST_CHRONO_MAC_API)
-#include <boost/chrono/detail/inlined/mac/process_cpu_clocks.hpp>
-
-//----------------------------------------------------------------------------//
-// POSIX //
-//----------------------------------------------------------------------------//
-#elif defined(BOOST_CHRONO_POSIX_API)
-#include <boost/chrono/detail/inlined/posix/process_cpu_clocks.hpp>
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
-#endif // POSIX
+ if ( boost::detail::win32::GetProcessTimes(
+ boost::detail::win32::GetCurrentProcess(), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
+ ,
+ ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
+ | user_time.dwLowDateTime
+ ) * 100,
+ ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
+ | system_time.dwLowDateTime
+ ) * 100
+ );
+ return time_point(duration(r));
+ }
+ else
+ {
+ BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
+ return time_point();
+ }
+
+}
+
+#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
+process_cpu_clock::time_point process_cpu_clock::now(
+ system::error_code & ec )
+{
+
+ // note that Windows uses 100 nanosecond ticks for FILETIME
+ boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
+
+ if ( boost::detail::win32::GetProcessTimes(
+ boost::detail::win32::GetCurrentProcess(), &creation, &exit,
+ &system_time, &user_time ) )
+ {
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ {
+ ec.clear();
+ }
+ time_point::rep r(process_real_cpu_clock::now().time_since_epoch().count()
+ ,
+ ((static_cast<process_user_cpu_clock::rep>(user_time.dwHighDateTime) << 32)
+ | user_time.dwLowDateTime
+ ) * 100,
+ ((static_cast<process_system_cpu_clock::rep>(system_time.dwHighDateTime) << 32)
+ | system_time.dwLowDateTime
+ ) * 100
+ );
+ return time_point(duration(r));
+ }
+ else
+ {
+ boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
+ if (BOOST_CHRONO_IS_THROWS(ec))
+ {
+ boost::throw_exception(
+ system::system_error(
+ cause,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
+ "chrono::process_cpu_clock" ));
+ }
+ else
+ {
+ ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
+ return time_point();
+ }
+ }
+}
#endif
+} // namespace chrono
+} // namespace boost
#endif
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