1 // Copyright (c) 2020 Andrey Semashev
3 // Distributed under the Boost Software License, Version 1.0.
4 // See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_ATOMIC_TEST_TEST_CLOCK_HPP_INCLUDED_
8 #define BOOST_ATOMIC_TEST_TEST_CLOCK_HPP_INCLUDED_
10 #include <boost/config.hpp>
11 #if defined(BOOST_WINDOWS)
12 #include <boost/winapi/config.hpp>
13 #include <boost/winapi/basic_types.hpp>
14 #include <boost/winapi/time.hpp>
15 #include <boost/ratio/ratio.hpp>
17 #include <boost/chrono/chrono.hpp>
19 namespace chrono = boost::chrono;
21 #if defined(BOOST_WINDOWS)
23 // On Windows high precision clocks tend to cause spurious test failures because threads wake up earlier than expected.
24 // Use a lower precision steady clock for tests.
27 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
28 typedef boost::winapi::ULONGLONG_ rep;
30 typedef boost::winapi::DWORD_ rep;
32 typedef boost::milli period;
33 typedef chrono::duration< rep, period > duration;
34 typedef chrono::time_point< test_clock, duration > time_point;
36 static BOOST_CONSTEXPR_OR_CONST bool is_steady = true;
38 static time_point now() BOOST_NOEXCEPT
40 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
41 rep ticks = boost::winapi::GetTickCount64();
43 rep ticks = boost::winapi::GetTickCount();
45 return time_point(duration(ticks));
49 #elif defined(BOOST_CHRONO_HAS_CLOCK_STEADY)
50 typedef chrono::steady_clock test_clock;
52 typedef chrono::system_clock test_clock;
55 #endif // BOOST_ATOMIC_TEST_TEST_CLOCK_HPP_INCLUDED_