File indexing completed on 2026-09-09 08:48:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_TIMED_UTILS_HPP
0012 #define BOOST_INTERPROCESS_TIMED_UTILS_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 # pragma once
0021 #endif
0022
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 #include <boost/interprocess/detail/timed_utils.hpp>
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 namespace boost {
0036 namespace interprocess {
0037
0038
0039
0040 class ustime;
0041
0042
0043
0044 class usduration
0045 {
0046 public:
0047 friend class ustime;
0048
0049
0050
0051 explicit usduration(boost::uint64_t microsecs = 0u)
0052 : m_microsecs(microsecs)
0053 {}
0054
0055
0056
0057 boost::uint64_t get_microsecs() const
0058 { return m_microsecs; }
0059
0060 bool operator < (const usduration &other) const
0061 { return m_microsecs < other.m_microsecs; }
0062
0063 bool operator > (const usduration &other) const
0064 { return m_microsecs > other.m_microsecs; }
0065
0066 bool operator <= (const usduration &other) const
0067 { return m_microsecs <= other.m_microsecs; }
0068
0069 bool operator >= (const usduration &other) const
0070 { return m_microsecs >= other.m_microsecs; }
0071
0072 private:
0073 boost::uint64_t m_microsecs;
0074 };
0075
0076 class ustime
0077 {
0078 public:
0079
0080
0081 explicit ustime(boost::uint64_t microsecs = 0u)
0082 : m_microsecs(microsecs)
0083 {}
0084
0085 ustime &operator += (const usduration &other)
0086 { m_microsecs += other.m_microsecs; return *this; }
0087
0088 ustime operator + (const usduration &other)
0089 { ustime r(*this); r += other; return r; }
0090
0091 ustime &operator -= (const usduration &other)
0092 { m_microsecs -= other.m_microsecs; return *this; }
0093
0094 ustime operator - (const usduration &other)
0095 { ustime r(*this); r -= other; return r; }
0096
0097 friend usduration operator - (const ustime &l, const ustime &r)
0098 { return usduration(l.m_microsecs - r.m_microsecs); }
0099
0100 bool operator < (const ustime &other) const
0101 { return m_microsecs < other.m_microsecs; }
0102
0103 bool operator > (const ustime &other) const
0104 { return m_microsecs > other.m_microsecs; }
0105
0106 bool operator <= (const ustime &other) const
0107 { return m_microsecs <= other.m_microsecs; }
0108
0109 bool operator >= (const ustime &other) const
0110 { return m_microsecs >= other.m_microsecs; }
0111
0112
0113
0114 boost::uint64_t get_microsecs() const
0115 { return m_microsecs; }
0116
0117 private:
0118 boost::uint64_t m_microsecs;
0119 };
0120
0121
0122
0123 inline usduration usduration_from_seconds(boost::uint64_t sec)
0124 { return usduration(sec*uint64_t(1000000u)); }
0125
0126
0127
0128 inline usduration usduration_from_milliseconds(boost::uint64_t millisec)
0129 { return usduration(millisec*1000u); }
0130
0131
0132
0133 inline ustime ustime_delay_milliseconds(unsigned msecs)
0134 {
0135 return ustime(ipcdetail::universal_time_u64_us()) + usduration(msecs*1000u);
0136 }
0137
0138 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0139
0140 namespace ipcdetail {
0141
0142 template<>
0143 class microsec_clock<ustime>
0144 {
0145 public:
0146 typedef ustime time_point;
0147
0148 static ustime universal_time()
0149 { return ustime(universal_time_u64_us()); }
0150 };
0151
0152
0153
0154 template<class Duration>
0155 inline usduration duration_to_usduration(const Duration &d, typename enable_if_ptime_duration<Duration>::type* = 0)
0156 {
0157 return usduration(static_cast<boost::uint64_t>(d.total_microseconds()));
0158 }
0159
0160 template<class Duration>
0161 inline usduration duration_to_usduration(const Duration &d, typename enable_if_duration<Duration>::type* = 0)
0162 {
0163 const double factor = double(Duration::period::num)*1000000.0/double(Duration::period::den);
0164 return usduration(static_cast<boost::uint64_t>(double(d.count())*factor));
0165 }
0166
0167 inline usduration duration_to_usduration(const usduration &d)
0168 {
0169 return d;
0170 }
0171
0172
0173
0174 template<class Duration>
0175 inline ustime duration_to_ustime(const Duration &d)
0176 {
0177 return microsec_clock<ustime>::universal_time() + (duration_to_usduration)(d);
0178 }
0179
0180
0181 }
0182
0183 #endif
0184
0185 }
0186 }
0187
0188 #include <boost/interprocess/detail/config_end.hpp>
0189
0190 #endif