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