]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/atomic/test/test_clock.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / atomic / test / test_clock.hpp
1 // Copyright (c) 2020 Andrey Semashev
2 //
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)
6
7 #ifndef BOOST_ATOMIC_TEST_TEST_CLOCK_HPP_INCLUDED_
8 #define BOOST_ATOMIC_TEST_TEST_CLOCK_HPP_INCLUDED_
9
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>
16 #endif
17 #include <boost/chrono/chrono.hpp>
18
19 namespace chrono = boost::chrono;
20
21 #if defined(BOOST_WINDOWS)
22
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.
25 struct test_clock
26 {
27 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
28 typedef boost::winapi::ULONGLONG_ rep;
29 #else
30 typedef boost::winapi::DWORD_ rep;
31 #endif
32 typedef boost::milli period;
33 typedef chrono::duration< rep, period > duration;
34 typedef chrono::time_point< test_clock, duration > time_point;
35
36 static BOOST_CONSTEXPR_OR_CONST bool is_steady = true;
37
38 static time_point now() BOOST_NOEXCEPT
39 {
40 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
41 rep ticks = boost::winapi::GetTickCount64();
42 #else
43 rep ticks = boost::winapi::GetTickCount();
44 #endif
45 return time_point(duration(ticks));
46 }
47 };
48
49 #elif defined(BOOST_CHRONO_HAS_CLOCK_STEADY)
50 typedef chrono::steady_clock test_clock;
51 #else
52 typedef chrono::system_clock test_clock;
53 #endif
54
55 #endif // BOOST_ATOMIC_TEST_TEST_CLOCK_HPP_INCLUDED_