]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/stopwatches/include/boost/chrono/stopwatches/strict_stopwatch.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / include / boost / chrono / stopwatches / strict_stopwatch.hpp
1 // boost/chrono/stopwatches/strict_stopwatch.hpp ------------------------------------------------------------//
2 // Copyright 2011 Vicente J. Botet Escriba
3 // Copyright (c) Microsoft Corporation 2014
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/libs/chrono/stopwatches for documentation.
7
8 #ifndef BOOST_CHRONO_STOPWATCHES_STRICT_STOPWATCH__HPP
9 #define BOOST_CHRONO_STOPWATCHES_STRICT_STOPWATCH__HPP
10
11 #include <boost/chrono/config.hpp>
12
13 #include <boost/chrono/chrono.hpp>
14 #include <boost/chrono/detail/system.hpp>
15 #include <boost/chrono/thread_clock.hpp>
16 #include <boost/chrono/process_cpu_clocks.hpp>
17 #include <utility>
18
19 namespace boost
20 {
21 namespace chrono
22 {
23
24 /**
25 * This class provides the simpler stopwatch which is just able to give the elapsed time since its construction.
26 */
27 template<typename Clock=high_resolution_clock>
28 class strict_stopwatch
29 {
30 public:
31 typedef Clock clock;
32 typedef typename Clock::duration duration;
33 typedef typename Clock::time_point time_point;
34 typedef typename Clock::rep rep;
35 typedef typename Clock::period period;
36 BOOST_STATIC_CONSTEXPR bool is_steady = Clock::is_steady;
37
38
39 strict_stopwatch() :
40 start_(clock::now())
41 {
42 }
43 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
44 explicit strict_stopwatch(system::error_code & ec) :
45 start_(duration::zero())
46 {
47 time_point tmp = clock::now(ec);
48 if (!BOOST_CHRONO_IS_THROWS(ec))
49 {
50 if (ec)
51 {
52 return;
53 }
54 }
55 start_ = tmp;
56 }
57 #endif
58
59 ~strict_stopwatch() BOOST_NOEXCEPT
60 {
61 }
62
63 duration elapsed()
64 {
65 return clock::now() - start_;
66 }
67
68 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
69 duration elapsed(system::error_code & ec)
70 {
71 time_point tmp = clock::now(ec);
72 if (!BOOST_CHRONO_IS_THROWS(ec))
73 {
74 if (ec)
75 return duration::zero();
76 }
77 return tmp - start_;
78 }
79 #endif
80 /**
81 * States if the Stopwatch is running.
82 */
83 bool is_running() const {
84 return true;
85 }
86 private:
87 time_point start_;
88 strict_stopwatch(const strict_stopwatch&); // = delete;
89 strict_stopwatch& operator=(const strict_stopwatch&); // = delete;
90 };
91
92 typedef strict_stopwatch<system_clock> system_strict_stopwatch;
93 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
94 typedef strict_stopwatch<steady_clock> steady_strict_stopwatch;
95 #endif
96 typedef strict_stopwatch<high_resolution_clock> high_resolution_strict_stopwatch;
97
98 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
99 typedef strict_stopwatch<process_real_cpu_clock> process_real_cpu_strict_stopwatch;
100 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
101 typedef strict_stopwatch<process_user_cpu_clock> process_user_cpu_strict_stopwatch;
102 typedef strict_stopwatch<process_system_cpu_clock> process_system_cpu_strict_stopwatch;
103 typedef strict_stopwatch<process_cpu_clock> process_cpu_strict_stopwatch;
104 #endif
105 #endif
106
107 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
108 typedef strict_stopwatch<thread_clock> thread_strict_stopwatch;
109 #endif
110
111
112 } // namespace chrono
113 } // namespace boost
114
115 #endif