]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * Copyright Andrey Semashev 2007 - 2015. | |
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 | /*! | |
8 | * \file timestamp.hpp | |
9 | * \author Andrey Semashev | |
10 | * \date 31.07.2011 | |
11 | * | |
12 | * \brief This header is the Boost.Log library implementation, see the library documentation | |
13 | * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. | |
14 | */ | |
15 | ||
16 | #ifndef BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_ | |
17 | #define BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_ | |
18 | ||
19 | #include <boost/cstdint.hpp> | |
20 | #include <boost/log/detail/config.hpp> | |
21 | #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__) | |
b32b8144 | 22 | #include <boost/winapi/basic_types.hpp> |
7c673cae FG |
23 | #endif |
24 | #include <boost/log/detail/header.hpp> | |
25 | ||
26 | #ifdef BOOST_HAS_PRAGMA_ONCE | |
27 | #pragma once | |
28 | #endif | |
29 | ||
30 | namespace boost { | |
31 | ||
32 | BOOST_LOG_OPEN_NAMESPACE | |
33 | ||
34 | namespace aux { | |
35 | ||
36 | /*! | |
37 | * Duration between two timestamps | |
38 | */ | |
39 | class duration | |
40 | { | |
41 | int64_t m_ticks; | |
42 | ||
43 | public: | |
20effc67 | 44 | explicit duration(int64_t ticks = 0) BOOST_NOEXCEPT : m_ticks(ticks) {} |
7c673cae FG |
45 | |
46 | #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__) | |
47 | int64_t milliseconds() const { return m_ticks; } | |
48 | #else | |
49 | BOOST_LOG_API int64_t milliseconds() const; | |
50 | #endif | |
51 | }; | |
52 | ||
53 | /*! | |
54 | * Opaque timestamp class | |
55 | */ | |
56 | class timestamp | |
57 | { | |
58 | uint64_t m_ticks; | |
59 | ||
60 | public: | |
20effc67 | 61 | explicit timestamp(uint64_t ticks = 0) BOOST_NOEXCEPT : m_ticks(ticks) {} |
7c673cae FG |
62 | |
63 | duration operator- (timestamp that) const | |
64 | { | |
65 | return duration(m_ticks - that.m_ticks); | |
66 | } | |
67 | }; | |
68 | ||
69 | /*! | |
70 | * \fn get_timestamp | |
71 | * | |
72 | * The function returns a timestamp, in opaque units since an unspecified | |
73 | * time point. This timer is guaranteed to be monotonic, it should not | |
74 | * be affected by clock changes, either manual or seasonal. Also, it | |
75 | * should be as fast as possible. | |
76 | */ | |
77 | #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__) | |
78 | ||
92f5a8d4 | 79 | typedef uint64_t (BOOST_WINAPI_WINAPI_CC* get_tick_count_t)(); |
7c673cae FG |
80 | extern BOOST_LOG_API get_tick_count_t get_tick_count; |
81 | ||
82 | inline timestamp get_timestamp() | |
83 | { | |
84 | return timestamp(get_tick_count()); | |
85 | } | |
86 | ||
87 | #else | |
88 | ||
89 | typedef timestamp (*get_timestamp_t)(); | |
90 | extern BOOST_LOG_API get_timestamp_t get_timestamp; | |
91 | ||
92 | #endif | |
93 | ||
94 | } // namespace aux | |
95 | ||
96 | BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
97 | ||
98 | } // namespace boost | |
99 | ||
100 | #include <boost/log/detail/footer.hpp> | |
101 | ||
102 | #endif // BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_ |