File indexing completed on 2025-01-18 09:29:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <time.h> // for clock_gettime
0014 #include <boost/assert.hpp>
0015 #include <boost/predef/os.h>
0016
0017 namespace boost
0018 {
0019 namespace chrono
0020 {
0021
0022 system_clock::time_point system_clock::now() BOOST_NOEXCEPT
0023 {
0024 timespec ts;
0025 if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
0026 {
0027 BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
0028 }
0029
0030 return time_point(duration(
0031 static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
0032 }
0033
0034 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0035 system_clock::time_point system_clock::now(system::error_code & ec)
0036 {
0037 timespec ts;
0038 if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
0039 {
0040 if (::boost::chrono::is_throws(ec))
0041 {
0042 boost::throw_exception(
0043 system::system_error(
0044 errno,
0045 ::boost::system::system_category(),
0046 "chrono::system_clock" ));
0047 }
0048 else
0049 {
0050 ec.assign( errno, ::boost::system::system_category() );
0051 return time_point();
0052 }
0053 }
0054
0055 if (!::boost::chrono::is_throws(ec))
0056 {
0057 ec.clear();
0058 }
0059 return time_point(duration(
0060 static_cast<system_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
0061 }
0062 #endif
0063
0064 std::time_t system_clock::to_time_t(const system_clock::time_point& t) BOOST_NOEXCEPT
0065 {
0066 return static_cast<std::time_t>( t.time_since_epoch().count() / 1000000000 );
0067 }
0068
0069 system_clock::time_point system_clock::from_time_t(std::time_t t) BOOST_NOEXCEPT
0070 {
0071 return time_point(duration(static_cast<system_clock::rep>(t) * 1000000000));
0072 }
0073
0074 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
0075
0076 steady_clock::time_point steady_clock::now() BOOST_NOEXCEPT
0077 {
0078 timespec ts;
0079 #if BOOST_OS_CYGWIN
0080
0081
0082
0083 do
0084 {
0085 #endif
0086 if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
0087 {
0088 BOOST_ASSERT(0 && "Boost::Chrono - Internal Error");
0089 }
0090 #if BOOST_OS_CYGWIN
0091 } while (ts.tv_sec == 0 && ts.tv_nsec == 0);
0092 #endif
0093 return time_point(duration(
0094 static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
0095 }
0096
0097 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
0098 steady_clock::time_point steady_clock::now(system::error_code & ec)
0099 {
0100 timespec ts;
0101 #if BOOST_OS_CYGWIN
0102
0103
0104
0105 do
0106 {
0107 #endif
0108 if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
0109 {
0110 if (::boost::chrono::is_throws(ec))
0111 {
0112 boost::throw_exception(
0113 system::system_error(
0114 errno,
0115 ::boost::system::system_category(),
0116 "chrono::steady_clock" ));
0117 }
0118 else
0119 {
0120 ec.assign( errno, ::boost::system::system_category() );
0121 return time_point();
0122 }
0123 }
0124 #if BOOST_OS_CYGWIN
0125 } while (ts.tv_sec == 0 && ts.tv_nsec == 0);
0126 #endif
0127
0128 if (!::boost::chrono::is_throws(ec))
0129 {
0130 ec.clear();
0131 }
0132 return time_point(duration(
0133 static_cast<steady_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
0134 }
0135 #endif
0136 #endif
0137
0138 }
0139 }
0140
0141