File indexing completed on 2026-08-17 08:38:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_ATOMIC_DETAIL_CHRONO_HPP_INCLUDED_
0015 #define BOOST_ATOMIC_DETAIL_CHRONO_HPP_INCLUDED_
0016
0017 #include <time.h>
0018 #include <chrono>
0019 #if !defined(__cpp_lib_chrono) || (__cpp_lib_chrono < 201510l)
0020 #include <ratio>
0021 #include <type_traits>
0022 #endif
0023 #if defined(CLOCK_REALTIME)
0024 #include <boost/atomic/posix_clock_traits_fwd.hpp>
0025 #endif
0026 #include <boost/atomic/detail/config.hpp>
0027 #include <boost/atomic/detail/header.hpp>
0028
0029 #ifdef BOOST_HAS_PRAGMA_ONCE
0030 #pragma once
0031 #endif
0032
0033 namespace boost {
0034 namespace atomics {
0035 namespace detail {
0036 namespace chrono {
0037
0038 #if defined(__cpp_lib_chrono) && (__cpp_lib_chrono >= 201510l)
0039
0040 using std::chrono::ceil;
0041
0042 #else
0043
0044 template< typename To, typename Rep, typename Period >
0045 inline constexpr To ceil(std::chrono::duration< Rep, Period > from) noexcept
0046 {
0047 using conv_ratio = std::ratio_divide< Period, typename To::period >;
0048 using common_rep = typename std::common_type< Rep, typename To::rep, decltype(conv_ratio::num) >::type;
0049 return To(static_cast< typename To::rep >((static_cast< common_rep >(from.count()) * conv_ratio::num) / conv_ratio::den +
0050 static_cast< common_rep >(((static_cast< common_rep >(from.count()) * conv_ratio::num) % conv_ratio::den) != static_cast< common_rep >(0))));
0051 }
0052
0053 #endif
0054
0055 }
0056 }
0057
0058 #if defined(CLOCK_REALTIME)
0059
0060
0061 template< >
0062 struct posix_clock_traits< std::chrono::system_clock >
0063 {
0064
0065 static constexpr clockid_t clock_id = CLOCK_REALTIME;
0066
0067
0068 static timespec to_timespec(std::chrono::system_clock::time_point time_point) noexcept
0069 {
0070 timespec ts{};
0071 std::chrono::nanoseconds::rep time_ns = std::chrono::duration_cast< std::chrono::nanoseconds >(time_point.time_since_epoch()).count();
0072
0073
0074 ts.tv_sec = std::chrono::system_clock::to_time_t(std::chrono::system_clock::time_point()) + static_cast< decltype(ts.tv_sec) >(time_ns / 1000000000);
0075 time_ns %= 1000000000;
0076 if (BOOST_UNLIKELY(time_ns < 0))
0077 {
0078 --ts.tv_sec;
0079 time_ns += 1000000000;
0080 }
0081 ts.tv_nsec = static_cast< decltype(ts.tv_nsec) >(time_ns);
0082 return ts;
0083 }
0084 };
0085
0086 #endif
0087
0088 }
0089 }
0090
0091 #include <boost/atomic/detail/footer.hpp>
0092
0093 #endif