// 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. //--------------------------------------------------------------------------------------// #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_THREAD_CLOCK_HPP #define BOOST_CHRONO_DETAIL_INLINED_WIN_THREAD_CLOCK_HPP #include #include #include #include #include #include #include namespace lslboost { namespace chrono { #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING thread_clock::time_point thread_clock::now( system::error_code & ec ) { // note that Windows uses 100 nanosecond ticks for FILETIME lslboost::detail::winapi::FILETIME_ creation, exit, user_time, system_time; if ( lslboost::detail::winapi::GetThreadTimes( lslboost::detail::winapi::GetCurrentThread (), &creation, &exit, &system_time, &user_time ) ) { duration user = duration( ((static_cast(user_time.dwHighDateTime) << 32) | user_time.dwLowDateTime) * 100 ); duration system = duration( ((static_cast(system_time.dwHighDateTime) << 32) | system_time.dwLowDateTime) * 100 ); if (!::lslboost::chrono::is_throws(ec)) { ec.clear(); } return time_point(system+user); } else { if (::lslboost::chrono::is_throws(ec)) { lslboost::throw_exception( system::system_error( lslboost::detail::winapi::GetLastError(), ::lslboost::system::system_category(), "chrono::thread_clock" )); } else { ec.assign( lslboost::detail::winapi::GetLastError(), ::lslboost::system::system_category() ); return thread_clock::time_point(duration(0)); } } } #endif thread_clock::time_point thread_clock::now() BOOST_NOEXCEPT { // note that Windows uses 100 nanosecond ticks for FILETIME lslboost::detail::winapi::FILETIME_ creation, exit, user_time, system_time; if ( lslboost::detail::winapi::GetThreadTimes( lslboost::detail::winapi::GetCurrentThread (), &creation, &exit, &system_time, &user_time ) ) { duration user = duration( ((static_cast(user_time.dwHighDateTime) << 32) | user_time.dwLowDateTime) * 100 ); duration system = duration( ((static_cast(system_time.dwHighDateTime) << 32) | system_time.dwLowDateTime) * 100 ); return time_point(system+user); } else { BOOST_ASSERT(0 && "Boost::Chrono - Internal Error"); return time_point(); } } } // namespace chrono } // namespace lslboost #endif