File indexing completed on 2025-01-18 09:29:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_CHRONO_HPP
0013 #define BOOST_CHRONO_DETAIL_INLINED_WIN_CHRONO_HPP
0014
0015 #include <boost/winapi/time.hpp>
0016 #include <boost/winapi/timers.hpp>
0017 #include <boost/winapi/get_last_error.hpp>
0018 #include <boost/winapi/error_codes.hpp>
0019 #include <boost/assert.hpp>
0020
0021 namespace boost
0022 {
0023 namespace chrono
0024 {
0025 namespace chrono_detail
0026 {
0027
0028 BOOST_CHRONO_INLINE double get_nanosecs_per_tic() BOOST_NOEXCEPT
0029 {
0030 boost::winapi::LARGE_INTEGER_ freq;
0031 if ( !boost::winapi::QueryPerformanceFrequency( &freq ) )
0032 return 0.0L;
0033 return double(1000000000.0L / freq.QuadPart);
0034 }
0035
0036 }
0037
0038 steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT
0039 {
0040 double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic();
0041
0042 boost::winapi::LARGE_INTEGER_ pcount;
0043 if ( nanosecs_per_tic <= 0.0L )
0044 {
0045 BOOST_ASSERT(0 && "Boost::Chrono - get_nanosecs_per_tic Internal Error");
0046 return steady_clock::time_point();
0047 }
0048 unsigned times=0;
0049 while ( ! boost::winapi::QueryPerformanceCounter( &pcount ) )
0050 {
0051 if ( ++times > 3 )
0052 {
0053 BOOST_ASSERT(0 && "Boost::Chrono - QueryPerformanceCounter Internal Error");
0054 return steady_clock::time_point();
0055 }
0056 }
0057
0058 return steady_clock::time_point(steady_clock::duration(
0059 static_cast<steady_clock::rep>((nanosecs_per_tic) * pcount.QuadPart)));
0060 }
0061
0062
0063 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0064 steady_clock::time_point steady_clock::now( system::error_code & ec )
0065 {
0066 double nanosecs_per_tic = chrono_detail::get_nanosecs_per_tic();
0067
0068 boost::winapi::LARGE_INTEGER_ pcount;
0069 if ( (nanosecs_per_tic <= 0.0L)
0070 || (!boost::winapi::QueryPerformanceCounter( &pcount )) )
0071 {
0072 boost::winapi::DWORD_ cause =
0073 ((nanosecs_per_tic <= 0.0L)
0074 ? boost::winapi::ERROR_NOT_SUPPORTED_
0075 : boost::winapi::GetLastError());
0076 if (::boost::chrono::is_throws(ec)) {
0077 boost::throw_exception(
0078 system::system_error(
0079 cause,
0080 ::boost::system::system_category(),
0081 "chrono::steady_clock" ));
0082 }
0083 else
0084 {
0085 ec.assign( cause, ::boost::system::system_category() );
0086 return steady_clock::time_point(duration(0));
0087 }
0088 }
0089
0090 if (!::boost::chrono::is_throws(ec))
0091 {
0092 ec.clear();
0093 }
0094 return time_point(duration(
0095 static_cast<steady_clock::rep>(nanosecs_per_tic * pcount.QuadPart)));
0096 }
0097 #endif
0098
0099 BOOST_CHRONO_INLINE
0100 system_clock::time_point system_clock::now() BOOST_NOEXCEPT
0101 {
0102 boost::winapi::FILETIME_ ft;
0103 boost::winapi::GetSystemTimeAsFileTime( &ft );
0104 return system_clock::time_point(
0105 system_clock::duration(
0106 ((static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime)
0107 - 116444736000000000LL
0108
0109 )
0110 );
0111 }
0112
0113 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0114 BOOST_CHRONO_INLINE
0115 system_clock::time_point system_clock::now( system::error_code & ec )
0116 {
0117 boost::winapi::FILETIME_ ft;
0118 boost::winapi::GetSystemTimeAsFileTime( &ft );
0119 if (!::boost::chrono::is_throws(ec))
0120 {
0121 ec.clear();
0122 }
0123 return system_clock::time_point(
0124 system_clock::duration(
0125 ((static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime)
0126 - 116444736000000000LL
0127
0128 ));
0129 }
0130 #endif
0131
0132 BOOST_CHRONO_INLINE
0133 std::time_t system_clock::to_time_t(const system_clock::time_point& t) BOOST_NOEXCEPT
0134 {
0135 __int64 temp = t.time_since_epoch().count();
0136 temp /= 10000000;
0137 return static_cast<std::time_t>( temp );
0138 }
0139
0140 BOOST_CHRONO_INLINE
0141 system_clock::time_point system_clock::from_time_t(std::time_t t) BOOST_NOEXCEPT
0142 {
0143 __int64 temp = t;
0144 temp *= 10000000;
0145 return time_point(duration(temp));
0146 }
0147
0148 }
0149 }
0150
0151 #endif