diff --git a/include/boost/move/detail/nsec_clock.hpp b/include/boost/move/detail/nsec_clock.hpp index 1919062..61b575a 100644 --- a/include/boost/move/detail/nsec_clock.hpp +++ b/include/boost/move/detail/nsec_clock.hpp @@ -25,6 +25,8 @@ #define BOOST_MOVE_DETAIL_NSEC_CLOCK_HPP #include +#include +#include # if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) @@ -42,32 +44,40 @@ #include #include #include +#include namespace boost { namespace move_detail { +template +struct QPFHolder +{ + static inline double get_nsec_per_tic() + { + boost::winapi::LARGE_INTEGER_ freq; + boost::winapi::BOOL_ r = boost::winapi::QueryPerformanceFrequency( &freq ); + boost::ignore_unused(r); + BOOST_ASSERT(r != 0 && "Boost::Move - get_nanosecs_per_tic Internal Error"); + + return double(1000000000.0L / freq.QuadPart); + } + + static const double nanosecs_per_tic; +}; + +template +const double QPFHolder::nanosecs_per_tic = get_nsec_per_tic(); + inline boost::uint64_t nsec_clock() BOOST_NOEXCEPT { - boost::winapi::LARGE_INTEGER_ freq; - if ( !boost::winapi::QueryPerformanceFrequency( &freq ) ) - { - BOOST_ASSERT(0 && "Boost::Move - get_nanosecs_per_tic Internal Error"); - return 0u; - } - - double nanosecs_per_tic = double(1000000000.0L / freq.QuadPart); - + double nanosecs_per_tic = QPFHolder<0>::nanosecs_per_tic; + boost::winapi::LARGE_INTEGER_ pcount; - if ( nanosecs_per_tic <= 0.0L ) - { - BOOST_ASSERT(0 && "Boost::Move - get_nanosecs_per_tic Internal Error"); - return 0u; - } unsigned times=0; - while ( ! boost::winapi::QueryPerformanceCounter( &pcount ) ) + while ( !boost::winapi::QueryPerformanceCounter( &pcount ) ) { if ( ++times > 3 ) { - BOOST_ASSERT(0 && "Boost::Move - QueryPerformanceCounter Internal Error"); + BOOST_ASSERT("Boost::Move - QueryPerformanceCounter Internal Error"); return 0u; } }