123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #ifndef BOOST_INTERPROCESS_TIMED_UTILS_HPP
- #define BOOST_INTERPROCESS_TIMED_UTILS_HPP
- #ifndef BOOST_CONFIG_HPP
- # include <boost/config.hpp>
- #endif
- #
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- #include <boost/interprocess/detail/config_begin.hpp>
- #include <boost/interprocess/detail/workaround.hpp>
- #include <boost/interprocess/detail/timed_utils.hpp>
- namespace boost {
- namespace interprocess {
- class ustime;
- class usduration
- {
- public:
- friend class ustime;
-
-
- explicit usduration(boost::uint64_t microsecs = 0u)
- : m_microsecs(microsecs)
- {}
-
-
- boost::uint64_t get_microsecs() const
- { return m_microsecs; }
- bool operator < (const usduration &other) const
- { return m_microsecs < other.m_microsecs; }
- bool operator > (const usduration &other) const
- { return m_microsecs > other.m_microsecs; }
- bool operator <= (const usduration &other) const
- { return m_microsecs <= other.m_microsecs; }
- bool operator >= (const usduration &other) const
- { return m_microsecs >= other.m_microsecs; }
- private:
- boost::uint64_t m_microsecs;
- };
- class ustime
- {
- public:
-
-
- explicit ustime(boost::uint64_t microsecs = 0u)
- : m_microsecs(microsecs)
- {}
- ustime &operator += (const usduration &other)
- { m_microsecs += other.m_microsecs; return *this; }
- ustime operator + (const usduration &other)
- { ustime r(*this); r += other; return r; }
- ustime &operator -= (const usduration &other)
- { m_microsecs -= other.m_microsecs; return *this; }
- ustime operator - (const usduration &other)
- { ustime r(*this); r -= other; return r; }
- friend usduration operator - (const ustime &l, const ustime &r)
- { return usduration(l.m_microsecs - r.m_microsecs); }
- bool operator < (const ustime &other) const
- { return m_microsecs < other.m_microsecs; }
- bool operator > (const ustime &other) const
- { return m_microsecs > other.m_microsecs; }
- bool operator <= (const ustime &other) const
- { return m_microsecs <= other.m_microsecs; }
- bool operator >= (const ustime &other) const
- { return m_microsecs >= other.m_microsecs; }
-
-
- boost::uint64_t get_microsecs() const
- { return m_microsecs; }
- private:
- boost::uint64_t m_microsecs;
- };
- inline usduration usduration_from_seconds(boost::uint64_t sec)
- { return usduration(sec*uint64_t(1000000u)); }
- inline usduration usduration_from_milliseconds(boost::uint64_t millisec)
- { return usduration(millisec*1000u); }
- inline ustime ustime_delay_milliseconds(unsigned msecs)
- {
- return ustime(ipcdetail::universal_time_u64_us()) + usduration(msecs*1000u);
- }
- #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
- namespace ipcdetail {
- template<>
- class microsec_clock<ustime>
- {
- public:
- typedef ustime time_point;
- static ustime universal_time()
- { return ustime(universal_time_u64_us()); }
- };
- template<class Duration>
- inline usduration duration_to_usduration(const Duration &d, typename enable_if_ptime_duration<Duration>::type* = 0)
- {
- return usduration(static_cast<boost::uint64_t>(d.total_microseconds()));
- }
- template<class Duration>
- inline usduration duration_to_usduration(const Duration &d, typename enable_if_duration<Duration>::type* = 0)
- {
- const double factor = double(Duration::period::num)*1000000.0/double(Duration::period::den);
- return usduration(static_cast<boost::uint64_t>(double(d.count())*factor));
- }
- inline usduration duration_to_usduration(const usduration &d)
- {
- return d;
- }
- template<class Duration>
- inline ustime duration_to_ustime(const Duration &d)
- {
- return microsec_clock<ustime>::universal_time() + (duration_to_usduration)(d);
- }
- }
- #endif
- }
- }
- #include <boost/interprocess/detail/config_end.hpp>
- #endif
|