File indexing completed on 2025-01-18 09:29:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_THREAD_CLOCK_HPP
0012 #define BOOST_CHRONO_DETAIL_INLINED_WIN_THREAD_CLOCK_HPP
0013
0014 #include <boost/chrono/config.hpp>
0015 #include <boost/chrono/thread_clock.hpp>
0016 #include <cassert>
0017 #include <boost/assert.hpp>
0018
0019 #include <boost/winapi/get_last_error.hpp>
0020 #include <boost/winapi/get_current_thread.hpp>
0021 #include <boost/winapi/get_thread_times.hpp>
0022
0023 namespace boost
0024 {
0025 namespace chrono
0026 {
0027
0028 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0029 thread_clock::time_point thread_clock::now( system::error_code & ec )
0030 {
0031
0032 boost::winapi::FILETIME_ creation, exit, user_time, system_time;
0033
0034 if ( boost::winapi::GetThreadTimes(
0035 boost::winapi::GetCurrentThread (), &creation, &exit,
0036 &system_time, &user_time ) )
0037 {
0038 duration user = duration(
0039 ((static_cast<duration::rep>(user_time.dwHighDateTime) << 32)
0040 | user_time.dwLowDateTime) * 100 );
0041
0042 duration system = duration(
0043 ((static_cast<duration::rep>(system_time.dwHighDateTime) << 32)
0044 | system_time.dwLowDateTime) * 100 );
0045
0046 if (!::boost::chrono::is_throws(ec))
0047 {
0048 ec.clear();
0049 }
0050 return time_point(system+user);
0051
0052 }
0053 else
0054 {
0055 if (::boost::chrono::is_throws(ec))
0056 {
0057 boost::throw_exception(
0058 system::system_error(
0059 boost::winapi::GetLastError(),
0060 ::boost::system::system_category(),
0061 "chrono::thread_clock" ));
0062 }
0063 else
0064 {
0065 ec.assign( boost::winapi::GetLastError(), ::boost::system::system_category() );
0066 return thread_clock::time_point(duration(0));
0067 }
0068 }
0069 }
0070 #endif
0071
0072 thread_clock::time_point thread_clock::now() BOOST_NOEXCEPT
0073 {
0074
0075
0076 boost::winapi::FILETIME_ creation, exit, user_time, system_time;
0077
0078 if ( boost::winapi::GetThreadTimes(
0079 boost::winapi::GetCurrentThread (), &creation, &exit,
0080 &system_time, &user_time ) )
0081 {
0082 duration user = duration(
0083 ((static_cast<duration::rep>(user_time.dwHighDateTime) << 32)
0084 | user_time.dwLowDateTime) * 100 );
0085
0086 duration system = duration(
0087 ((static_cast<duration::rep>(system_time.dwHighDateTime) << 32)
0088 | system_time.dwLowDateTime) * 100 );
0089
0090 return time_point(system+user);
0091 }
0092 else
0093 {
0094 BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
0095 return time_point();
0096 }
0097
0098 }
0099
0100 }
0101 }
0102
0103 #endif