Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:22

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   timestamp.hpp
0009  * \author Andrey Semashev
0010  * \date   31.07.2011
0011  *
0012  * \brief  This header is the Boost.Log library implementation, see the library documentation
0013  *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
0014  */
0015 
0016 #ifndef BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_
0017 #define BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_
0018 
0019 #include <boost/cstdint.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
0022 #include <boost/winapi/basic_types.hpp>
0023 #endif
0024 #include <boost/log/detail/header.hpp>
0025 
0026 #ifdef BOOST_HAS_PRAGMA_ONCE
0027 #pragma once
0028 #endif
0029 
0030 namespace boost {
0031 
0032 BOOST_LOG_OPEN_NAMESPACE
0033 
0034 namespace aux {
0035 
0036 /*!
0037  * Duration between two timestamps
0038  */
0039 class duration
0040 {
0041     int64_t m_ticks;
0042 
0043 public:
0044     explicit duration(int64_t ticks = 0) BOOST_NOEXCEPT : m_ticks(ticks) {}
0045 
0046 #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
0047     int64_t milliseconds() const { return m_ticks; }
0048 #else
0049     BOOST_LOG_API int64_t milliseconds() const;
0050 #endif
0051 };
0052 
0053 /*!
0054  * Opaque timestamp class
0055  */
0056 class timestamp
0057 {
0058     uint64_t m_ticks;
0059 
0060 public:
0061     explicit timestamp(uint64_t ticks = 0) BOOST_NOEXCEPT : m_ticks(ticks) {}
0062 
0063     duration operator- (timestamp that) const
0064     {
0065         return duration(m_ticks - that.m_ticks);
0066     }
0067 };
0068 
0069 /*!
0070  * \fn get_timestamp
0071  *
0072  * The function returns a timestamp, in opaque units since an unspecified
0073  * time point. This timer is guaranteed to be monotonic, it should not
0074  * be affected by clock changes, either manual or seasonal. Also, it
0075  * should be as fast as possible.
0076  */
0077 #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
0078 
0079 typedef uint64_t (BOOST_WINAPI_WINAPI_CC* get_tick_count_t)();
0080 extern BOOST_LOG_API get_tick_count_t get_tick_count;
0081 
0082 inline timestamp get_timestamp()
0083 {
0084     return timestamp(get_tick_count());
0085 }
0086 
0087 #else
0088 
0089 typedef timestamp (*get_timestamp_t)();
0090 extern BOOST_LOG_API get_timestamp_t get_timestamp;
0091 
0092 #endif
0093 
0094 } // namespace aux
0095 
0096 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0097 
0098 } // namespace boost
0099 
0100 #include <boost/log/detail/footer.hpp>
0101 
0102 #endif // BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_