annotate DEPENDENCIES/generic/include/boost/thread/xtime.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (C) 2001-2003
Chris@16 2 // William E. Kempf
Chris@16 3 // Copyright (C) 2007-8 Anthony Williams
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7
Chris@16 8 #ifndef BOOST_XTIME_WEK070601_HPP
Chris@16 9 #define BOOST_XTIME_WEK070601_HPP
Chris@16 10
Chris@16 11 #include <boost/thread/detail/config.hpp>
Chris@16 12 #if defined BOOST_THREAD_USES_DATETIME
Chris@16 13
Chris@16 14 #include <boost/cstdint.hpp>
Chris@16 15 #include <boost/thread/thread_time.hpp>
Chris@16 16 #include <boost/date_time/posix_time/conversion.hpp>
Chris@16 17
Chris@16 18 #include <boost/config/abi_prefix.hpp>
Chris@16 19
Chris@16 20 namespace boost {
Chris@16 21
Chris@16 22 enum xtime_clock_types
Chris@16 23 {
Chris@16 24 TIME_UTC_=1
Chris@16 25 // TIME_TAI,
Chris@16 26 // TIME_MONOTONIC,
Chris@16 27 // TIME_PROCESS,
Chris@16 28 // TIME_THREAD,
Chris@16 29 // TIME_LOCAL,
Chris@16 30 // TIME_SYNC,
Chris@16 31 // TIME_RESOLUTION
Chris@16 32 };
Chris@16 33
Chris@16 34 struct xtime
Chris@16 35 {
Chris@16 36 #if defined(BOOST_NO_INT64_T)
Chris@16 37 typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
Chris@16 38 #else
Chris@16 39 typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
Chris@16 40 #endif
Chris@16 41
Chris@16 42 typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
Chris@16 43
Chris@16 44 xtime_sec_t sec;
Chris@16 45 xtime_nsec_t nsec;
Chris@16 46
Chris@16 47 operator system_time() const
Chris@16 48 {
Chris@16 49 return boost::posix_time::from_time_t(0)+
Chris@16 50 boost::posix_time::seconds(static_cast<long>(sec))+
Chris@16 51 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
Chris@16 52 boost::posix_time::nanoseconds(nsec);
Chris@16 53 #else
Chris@16 54 boost::posix_time::microseconds((nsec+500)/1000);
Chris@16 55 #endif
Chris@16 56 }
Chris@16 57
Chris@16 58 };
Chris@16 59
Chris@16 60 inline xtime get_xtime(boost::system_time const& abs_time)
Chris@16 61 {
Chris@16 62 xtime res;
Chris@16 63 boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
Chris@16 64
Chris@16 65 res.sec=static_cast<xtime::xtime_sec_t>(time_since_epoch.total_seconds());
Chris@16 66 res.nsec=static_cast<xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
Chris@16 67 return res;
Chris@16 68 }
Chris@16 69
Chris@16 70 inline int xtime_get(struct xtime* xtp, int clock_type)
Chris@16 71 {
Chris@16 72 if (clock_type == TIME_UTC_)
Chris@16 73 {
Chris@16 74 *xtp=get_xtime(get_system_time());
Chris@16 75 return clock_type;
Chris@16 76 }
Chris@16 77 return 0;
Chris@16 78 }
Chris@16 79
Chris@16 80
Chris@16 81 inline int xtime_cmp(const xtime& xt1, const xtime& xt2)
Chris@16 82 {
Chris@16 83 if (xt1.sec == xt2.sec)
Chris@16 84 return (int)(xt1.nsec - xt2.nsec);
Chris@16 85 else
Chris@16 86 return (xt1.sec > xt2.sec) ? 1 : -1;
Chris@16 87 }
Chris@16 88
Chris@16 89 } // namespace boost
Chris@16 90
Chris@16 91 #include <boost/config/abi_suffix.hpp>
Chris@16 92 #endif
Chris@16 93 #endif //BOOST_XTIME_WEK070601_HPP