Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:09:32

0001 // Copyright (C) 2001-2003
0002 // William E. Kempf
0003 // Copyright (C) 2007-8 Anthony Williams
0004 //
0005 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
0006 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XTIME_WEK070601_HPP
0009 #define BOOST_XTIME_WEK070601_HPP
0010 
0011 #include <boost/thread/detail/config.hpp>
0012 #if defined BOOST_THREAD_USES_DATETIME
0013 
0014 #include <boost/cstdint.hpp>
0015 #include <boost/thread/thread_time.hpp>
0016 #include <boost/date_time/posix_time/conversion.hpp>
0017 
0018 #include <boost/config/abi_prefix.hpp>
0019 
0020 namespace boost {
0021 
0022 enum xtime_clock_types
0023 {
0024     TIME_UTC_=1
0025 //    TIME_TAI,
0026 //    TIME_MONOTONIC,
0027 //    TIME_PROCESS,
0028 //    TIME_THREAD,
0029 //    TIME_LOCAL,
0030 //    TIME_SYNC,
0031 //    TIME_RESOLUTION
0032 };
0033 
0034 struct xtime
0035 {
0036 #if defined(BOOST_NO_INT64_T)
0037     typedef int_fast32_t xtime_sec_t; //INT_FAST32_MIN <= sec <= INT_FAST32_MAX
0038 #else
0039     typedef int_fast64_t xtime_sec_t; //INT_FAST64_MIN <= sec <= INT_FAST64_MAX
0040 #endif
0041 
0042     typedef int_fast32_t xtime_nsec_t; //0 <= xtime.nsec < NANOSECONDS_PER_SECOND
0043 
0044     xtime_sec_t sec;
0045     xtime_nsec_t nsec;
0046 
0047     operator system_time() const
0048     {
0049         return boost::posix_time::from_time_t(0)+
0050             boost::posix_time::seconds(static_cast<long>(sec))+
0051 #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
0052             boost::posix_time::nanoseconds(nsec);
0053 #else
0054         boost::posix_time::microseconds((nsec+500)/1000);
0055 #endif
0056     }
0057 
0058 };
0059 
0060 inline ::boost::xtime get_xtime(boost::system_time const& abs_time)
0061 {
0062     ::boost::xtime res;
0063     boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
0064 
0065     res.sec=static_cast< ::boost::xtime::xtime_sec_t>(time_since_epoch.total_seconds());
0066     res.nsec=static_cast< ::boost::xtime::xtime_nsec_t>(time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()));
0067     return res;
0068 }
0069 
0070 inline int xtime_get(struct ::boost::xtime* xtp, int clock_type)
0071 {
0072     if (clock_type == TIME_UTC_)
0073     {
0074         *xtp=get_xtime(get_system_time());
0075         return clock_type;
0076     }
0077     return 0;
0078 }
0079 
0080 
0081 inline int xtime_cmp(const ::boost::xtime& xt1, const ::boost::xtime& xt2)
0082 {
0083     if (xt1.sec == xt2.sec)
0084         return (int)(xt1.nsec - xt2.nsec);
0085     else
0086         return (xt1.sec > xt2.sec) ? 1 : -1;
0087 }
0088 
0089 } // namespace boost
0090 
0091 #include <boost/config/abi_suffix.hpp>
0092 #endif
0093 #endif //BOOST_XTIME_WEK070601_HPP