Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file timestamp.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 31.07.2011 Chris@16: * Chris@16: * \brief This header is the Boost.Log library implementation, see the library documentation Chris@16: * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: /*! Chris@16: * Duration between two timestamps Chris@16: */ Chris@16: class duration Chris@16: { Chris@16: int64_t m_ticks; Chris@16: Chris@16: public: Chris@16: explicit duration(int64_t ticks = 0) : m_ticks(ticks) {} Chris@16: Chris@16: #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__) Chris@16: int64_t milliseconds() const { return m_ticks; } Chris@16: #else Chris@16: BOOST_LOG_API int64_t milliseconds() const; Chris@16: #endif Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * Opaque timestamp class Chris@16: */ Chris@16: class timestamp Chris@16: { Chris@16: uint64_t m_ticks; Chris@16: Chris@16: public: Chris@16: explicit timestamp(uint64_t ticks = 0) : m_ticks(ticks) {} Chris@16: Chris@16: duration operator- (timestamp that) const Chris@16: { Chris@16: return duration(m_ticks - that.m_ticks); Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * \fn get_timestamp Chris@16: * Chris@16: * The function returns a timestamp, in opaque units since an unspecified Chris@16: * time point. This timer is guaranteed to be monotonic, it should not Chris@16: * be affected by clock changes, either manual or seasonal. Also, it Chris@16: * should be as fast as possible. Chris@16: */ Chris@16: #if defined(BOOST_WINDOWS) && !defined(__CYGWIN__) Chris@16: Chris@16: typedef uint64_t (__stdcall* get_tick_count_t)(); Chris@16: extern BOOST_LOG_API get_tick_count_t get_tick_count; Chris@16: Chris@16: inline timestamp get_timestamp() Chris@16: { Chris@16: return timestamp(get_tick_count()); Chris@16: } Chris@16: Chris@16: #else Chris@16: Chris@16: typedef timestamp (*get_timestamp_t)(); Chris@16: extern BOOST_LOG_API get_timestamp_t get_timestamp; Chris@16: Chris@16: #endif Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_DETAIL_TIMESTAMP_HPP_INCLUDED_