diff --git a/include/boost/interprocess/detail/managed_open_or_create_impl.hpp b/include/boost/interprocess/detail/managed_open_or_create_impl.hpp index 84a89ad..ea7dc85 100644 --- a/include/boost/interprocess/detail/managed_open_or_create_impl.hpp +++ b/include/boost/interprocess/detail/managed_open_or_create_impl.hpp @@ -33,7 +33,7 @@ #include #include //alignment_of, aligned_storage #include -#include +#include #include #include @@ -388,7 +388,7 @@ class managed_open_or_create_impl , const void *addr, ConstructFunc construct_func , bool ronly, bool cow) { - const usduration TimeoutSec(usduration_seconds(MaxInitializeTimeSec)); + const usduration TimeoutSec(usduration_from_seconds(MaxInitializeTimeSec)); if(FileBased){ offset_t filesize = 0; diff --git a/include/boost/interprocess/detail/timed_utils.hpp b/include/boost/interprocess/detail/timed_utils.hpp index 88abb33..268b692 100644 --- a/include/boost/interprocess/detail/timed_utils.hpp +++ b/include/boost/interprocess/detail/timed_utils.hpp @@ -42,6 +42,10 @@ namespace boost { namespace interprocess { + +class ustime; +class usduration; + namespace ipcdetail { BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(time_duration_type) @@ -74,6 +78,16 @@ struct enable_if_duration : enable_if_c< BOOST_INTRUSIVE_HAS_TYPE(boost::interprocess::ipcdetail::, T, rep) > {}; +template +struct enable_if_ustime + : enable_if_c< is_same::value > +{}; + +template +struct enable_if_usduration + : enable_if_c< is_same::value > +{}; + #if defined(BOOST_INTERPROCESS_HAS_REENTRANT_STD_FUNCTIONS) inline std::tm* interprocess_gmtime(const std::time_t* t, std::tm* result) @@ -135,82 +149,24 @@ inline boost::uint64_t file_time_to_microseconds(const boost::winapi::FILETIME_ } #endif -class ustime; - -class usduration +inline boost::uint64_t universal_time_u64_us() { - public: - friend class ustime; + #ifdef BOOST_HAS_GETTIMEOFDAY + timeval tv; + gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux. + boost::uint64_t micros = boost::uint64_t(tv.tv_sec)*1000000u; + micros += (boost::uint64_t)tv.tv_usec; + #elif defined(BOOST_HAS_FTIME) + boost::winapi::FILETIME_ ft; + boost::winapi::GetSystemTimeAsFileTime(&ft); + boost::uint64_t micros = file_time_to_microseconds(ft); // it will not wrap, since ft is the current time + // and cannot be before 1970-Jan-01 + #else + #error "Unsupported date-time error: neither gettimeofday nor FILETIME support is detected" + #endif + return micros; +} - explicit usduration(boost::uint64_t microsecs) - : 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_milliseconds(boost::uint64_t millisec) -{ return usduration(millisec*1000u); } - -inline usduration usduration_seconds(boost::uint64_t sec) -{ return usduration(sec*uint64_t(1000000u)); } template class microsec_clock; @@ -266,31 +222,6 @@ class microsec_clock::type> } }; -template<> -class microsec_clock -{ - public: - typedef ustime time_point; - - static ustime universal_time() - { - #ifdef BOOST_HAS_GETTIMEOFDAY - timeval tv; - gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux. - boost::uint64_t micros = boost::uint64_t(tv.tv_sec)*1000000u; - micros += (boost::uint64_t)tv.tv_usec; - #elif defined(BOOST_HAS_FTIME) - boost::winapi::FILETIME_ ft; - boost::winapi::GetSystemTimeAsFileTime(&ft); - boost::uint64_t micros = file_time_to_microseconds(ft); // it will not wrap, since ft is the current time - // and cannot be before 1970-Jan-01 - #else - #error "Unsupported date-time error: neither gettimeofday nor FILETIME support is detected" - #endif - return ustime(micros); - } -}; - template class microsec_clock::type> { @@ -329,35 +260,12 @@ inline boost::uint64_t duration_to_milliseconds(const Duration &d, typename enab return static_cast(double(d.count())*factor); } -inline boost::uint64_t duration_to_milliseconds(const usduration &d) -{ - return d.get_microsecs()/1000; -} - -// duration_to_usduration - template -inline usduration duration_to_usduration(const Duration &d, typename enable_if_ptime_duration::type* = 0) +inline boost::uint64_t duration_to_milliseconds(const Duration&d, typename enable_if_usduration::type* = 0) { - return usduration(static_cast(d.total_microseconds())); + return d.get_microsecs()/1000u; } -template -inline usduration duration_to_usduration(const Duration &d, typename enable_if_duration::type* = 0) -{ - const double factor = double(Duration::period::num)*1000000.0/double(Duration::period::den); - return usduration(static_cast(double(d.count())*factor)); -} - -// duration_to_ustime - -template -inline ustime duration_to_ustime(const Duration &d) -{ - return microsec_clock::universal_time() + (duration_to_usduration)(d); -} - - } //namespace ipcdetail { } //namespace interprocess { } //namespace boost { diff --git a/include/boost/interprocess/ipc/message_queue.hpp b/include/boost/interprocess/ipc/message_queue.hpp index 4ef2678..c52ddfc 100644 --- a/include/boost/interprocess/ipc/message_queue.hpp +++ b/include/boost/interprocess/ipc/message_queue.hpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/boost/interprocess/segment_manager.hpp b/include/boost/interprocess/segment_manager.hpp index 379e419..d292c50 100644 --- a/include/boost/interprocess/segment_manager.hpp +++ b/include/boost/interprocess/segment_manager.hpp @@ -49,6 +49,7 @@ #ifndef BOOST_NO_EXCEPTIONS #include #endif +#include //!\file //!Describes the object placed in a memory segment that provides diff --git a/include/boost/interprocess/sync/detail/common_algorithms.hpp b/include/boost/interprocess/sync/detail/common_algorithms.hpp index 3cb1d1a..17aafa8 100644 --- a/include/boost/interprocess/sync/detail/common_algorithms.hpp +++ b/include/boost/interprocess/sync/detail/common_algorithms.hpp @@ -23,7 +23,7 @@ #include #include -#include +#include namespace boost { namespace interprocess { @@ -78,7 +78,7 @@ void timeout_when_locking_aware_lock(MutexType &m) { #ifdef BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING if (!m.timed_lock(microsec_clock::universal_time() - + usduration_milliseconds(BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS))) + + usduration_from_milliseconds(BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS))) { throw interprocess_exception(timeout_when_locking_error , "Interprocess mutex timeout when locking. Possible deadlock: " diff --git a/include/boost/interprocess/sync/file_lock.hpp b/include/boost/interprocess/sync/file_lock.hpp index a147837..34adbd5 100644 --- a/include/boost/interprocess/sync/file_lock.hpp +++ b/include/boost/interprocess/sync/file_lock.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/interprocess_condition.hpp b/include/boost/interprocess/sync/interprocess_condition.hpp index 24ca5b5..7fde9fe 100644 --- a/include/boost/interprocess/sync/interprocess_condition.hpp +++ b/include/boost/interprocess/sync/interprocess_condition.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/interprocess_condition_any.hpp b/include/boost/interprocess/sync/interprocess_condition_any.hpp index 6b076a9..4a1d84a 100644 --- a/include/boost/interprocess/sync/interprocess_condition_any.hpp +++ b/include/boost/interprocess/sync/interprocess_condition_any.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/interprocess_mutex.hpp b/include/boost/interprocess/sync/interprocess_mutex.hpp index 4eb1f59..3819080 100644 --- a/include/boost/interprocess/sync/interprocess_mutex.hpp +++ b/include/boost/interprocess/sync/interprocess_mutex.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp b/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp index 35950ae..bee9eed 100644 --- a/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp +++ b/include/boost/interprocess/sync/interprocess_sharable_mutex.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/interprocess_upgradable_mutex.hpp b/include/boost/interprocess/sync/interprocess_upgradable_mutex.hpp index 359a28f..7b7893a 100644 --- a/include/boost/interprocess/sync/interprocess_upgradable_mutex.hpp +++ b/include/boost/interprocess/sync/interprocess_upgradable_mutex.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/named_condition.hpp b/include/boost/interprocess/sync/named_condition.hpp index 9ea0182..78a9fb9 100644 --- a/include/boost/interprocess/sync/named_condition.hpp +++ b/include/boost/interprocess/sync/named_condition.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/named_condition_any.hpp b/include/boost/interprocess/sync/named_condition_any.hpp index 174ed9c..2614c46 100644 --- a/include/boost/interprocess/sync/named_condition_any.hpp +++ b/include/boost/interprocess/sync/named_condition_any.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/named_mutex.hpp b/include/boost/interprocess/sync/named_mutex.hpp index 9d74173..c741576 100644 --- a/include/boost/interprocess/sync/named_mutex.hpp +++ b/include/boost/interprocess/sync/named_mutex.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/interprocess/sync/named_recursive_mutex.hpp b/include/boost/interprocess/sync/named_recursive_mutex.hpp index 099bd51..e75d0f9 100644 --- a/include/boost/interprocess/sync/named_recursive_mutex.hpp +++ b/include/boost/interprocess/sync/named_recursive_mutex.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS) #include diff --git a/include/boost/interprocess/sync/named_sharable_mutex.hpp b/include/boost/interprocess/sync/named_sharable_mutex.hpp index 68ce8ef..d56e7b9 100644 --- a/include/boost/interprocess/sync/named_sharable_mutex.hpp +++ b/include/boost/interprocess/sync/named_sharable_mutex.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/interprocess/sync/named_upgradable_mutex.hpp b/include/boost/interprocess/sync/named_upgradable_mutex.hpp index eaf1283..679e961 100644 --- a/include/boost/interprocess/sync/named_upgradable_mutex.hpp +++ b/include/boost/interprocess/sync/named_upgradable_mutex.hpp @@ -28,6 +28,7 @@ #include #include #include +#include //!\file //!Describes a named upgradable mutex class for inter-process synchronization diff --git a/include/boost/interprocess/sync/posix/condition.hpp b/include/boost/interprocess/sync/posix/condition.hpp index f151a5b..5b3b752 100644 --- a/include/boost/interprocess/sync/posix/condition.hpp +++ b/include/boost/interprocess/sync/posix/condition.hpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/boost/interprocess/sync/posix/mutex.hpp b/include/boost/interprocess/sync/posix/mutex.hpp index 69cc162..8716f79 100644 --- a/include/boost/interprocess/sync/posix/mutex.hpp +++ b/include/boost/interprocess/sync/posix/mutex.hpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS diff --git a/include/boost/interprocess/sync/posix/named_mutex.hpp b/include/boost/interprocess/sync/posix/named_mutex.hpp index ac79b05..bdf3ea4 100644 --- a/include/boost/interprocess/sync/posix/named_mutex.hpp +++ b/include/boost/interprocess/sync/posix/named_mutex.hpp @@ -25,7 +25,7 @@ #include #include #include - +#include #include namespace boost { diff --git a/include/boost/interprocess/sync/posix/recursive_mutex.hpp b/include/boost/interprocess/sync/posix/recursive_mutex.hpp index bcd056d..20e654e 100644 --- a/include/boost/interprocess/sync/posix/recursive_mutex.hpp +++ b/include/boost/interprocess/sync/posix/recursive_mutex.hpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #ifndef BOOST_INTERPROCESS_POSIX_TIMEOUTS # include diff --git a/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp b/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp index 77ba486..c77397a 100644 --- a/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp +++ b/include/boost/interprocess/sync/posix/semaphore_wrapper.hpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include //O_CREAT, O_*... diff --git a/include/boost/interprocess/sync/posix/timepoint_to_timespec.hpp b/include/boost/interprocess/sync/posix/timepoint_to_timespec.hpp index 5869133..6f5d795 100644 --- a/include/boost/interprocess/sync/posix/timepoint_to_timespec.hpp +++ b/include/boost/interprocess/sync/posix/timepoint_to_timespec.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include namespace boost { diff --git a/include/boost/interprocess/sync/shm/named_condition.hpp b/include/boost/interprocess/sync/shm/named_condition.hpp index c363d3d..c9e7550 100644 --- a/include/boost/interprocess/sync/shm/named_condition.hpp +++ b/include/boost/interprocess/sync/shm/named_condition.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #if defined (BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES) #include #include diff --git a/include/boost/interprocess/sync/shm/named_condition_any.hpp b/include/boost/interprocess/sync/shm/named_condition_any.hpp index dae4354..31f6213 100644 --- a/include/boost/interprocess/sync/shm/named_condition_any.hpp +++ b/include/boost/interprocess/sync/shm/named_condition_any.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include //!\file diff --git a/include/boost/interprocess/sync/shm/named_mutex.hpp b/include/boost/interprocess/sync/shm/named_mutex.hpp index 1d25287..123f26a 100644 --- a/include/boost/interprocess/sync/shm/named_mutex.hpp +++ b/include/boost/interprocess/sync/shm/named_mutex.hpp @@ -30,6 +30,7 @@ #include #include #include +#include //!\file //!Describes a named mutex class for inter-process synchronization diff --git a/include/boost/interprocess/sync/shm/named_recursive_mutex.hpp b/include/boost/interprocess/sync/shm/named_recursive_mutex.hpp index 3902162..437588e 100644 --- a/include/boost/interprocess/sync/shm/named_recursive_mutex.hpp +++ b/include/boost/interprocess/sync/shm/named_recursive_mutex.hpp @@ -28,6 +28,7 @@ #include #include #include +#include //!\file //!Describes a named shm_named_recursive_mutex class for inter-process synchronization diff --git a/include/boost/interprocess/sync/spin/condition.hpp b/include/boost/interprocess/sync/spin/condition.hpp index 1416200..5eead3e 100644 --- a/include/boost/interprocess/sync/spin/condition.hpp +++ b/include/boost/interprocess/sync/spin/condition.hpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/boost/interprocess/sync/spin/mutex.hpp b/include/boost/interprocess/sync/spin/mutex.hpp index ce9f87f..2cccce2 100644 --- a/include/boost/interprocess/sync/spin/mutex.hpp +++ b/include/boost/interprocess/sync/spin/mutex.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace boost { namespace interprocess { diff --git a/include/boost/interprocess/sync/spin/recursive_mutex.hpp b/include/boost/interprocess/sync/spin/recursive_mutex.hpp index 3a9e94a..a2a8557 100644 --- a/include/boost/interprocess/sync/spin/recursive_mutex.hpp +++ b/include/boost/interprocess/sync/spin/recursive_mutex.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include namespace boost { diff --git a/include/boost/interprocess/sync/windows/condition.hpp b/include/boost/interprocess/sync/windows/condition.hpp index 255cb69..fca3f1f 100644 --- a/include/boost/interprocess/sync/windows/condition.hpp +++ b/include/boost/interprocess/sync/windows/condition.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include diff --git a/include/boost/interprocess/sync/windows/mutex.hpp b/include/boost/interprocess/sync/windows/mutex.hpp index e1bd190..ce168f8 100644 --- a/include/boost/interprocess/sync/windows/mutex.hpp +++ b/include/boost/interprocess/sync/windows/mutex.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace boost { diff --git a/include/boost/interprocess/sync/windows/named_condition_any.hpp b/include/boost/interprocess/sync/windows/named_condition_any.hpp index c00601c..f13a5f9 100644 --- a/include/boost/interprocess/sync/windows/named_condition_any.hpp +++ b/include/boost/interprocess/sync/windows/named_condition_any.hpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace boost { namespace interprocess { diff --git a/include/boost/interprocess/sync/windows/named_mutex.hpp b/include/boost/interprocess/sync/windows/named_mutex.hpp index b3d3246..029eb61 100644 --- a/include/boost/interprocess/sync/windows/named_mutex.hpp +++ b/include/boost/interprocess/sync/windows/named_mutex.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace boost { diff --git a/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp b/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp index b95af82..5dcb0be 100644 --- a/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp +++ b/include/boost/interprocess/sync/windows/winapi_wrapper_common.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include namespace boost { diff --git a/include/boost/interprocess/timed_utils.hpp b/include/boost/interprocess/timed_utils.hpp new file mode 100644 index 0000000..768203d --- /dev/null +++ b/include/boost/interprocess/timed_utils.hpp @@ -0,0 +1,189 @@ +//////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2023-2024. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTERPROCESS_TIMED_UTILS_HPP +#define BOOST_INTERPROCESS_TIMED_UTILS_HPP + +#ifndef BOOST_CONFIG_HPP +# include +#endif +# +#if defined(BOOST_HAS_PRAGMA_ONCE) +# pragma once +#endif + +#include +#include +#include + + +//!\file +//!Describes some simple time-related utilities that can be used to call synchronization primitive and ipc methods that required +//!waiting until the resource is signalled or a timeout expires. +//! +//! These utilities are provided for those users that want to avoid dependence on std::chrono or boost::chrono or boost::date_time +//! and just want to implement simple portable waits. + +namespace boost { +namespace interprocess { + +//!Describes a simple duration type with microsecond resolution that can be used with the ustime time-point utility to call timed functions +//! of Boost.Interprocess' synchronization classes that expect a time-point (timed_wait, wait_until, timed_lock, lock_until...) +class ustime; + +//!Describes a simple duration type with microsecond resolution that can be used with the ustime time-point utility to call timed functions +//! of Boost.Interprocess' synchronization classes that expect a duration type (wait_for, lock_for...) +class usduration +{ + public: + friend class ustime; + + //!Constructs a duration type that stores microseconds from + //!the passed count + explicit usduration(boost::uint64_t microsecs = 0u) + : m_microsecs(microsecs) + {} + + //!Returns the stored microsecond + //!count + 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: + //!Constructs a time point that is "microsecs" duration away + //!from the epoch of the system + 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; } + + //!Returns the stored count + //!that represents microseconds from epoch + boost::uint64_t get_microsecs() const + { return m_microsecs; } + + private: + boost::uint64_t m_microsecs; +}; + +//!Utility that returns a duration from +//!a seconds count +inline usduration usduration_from_seconds(boost::uint64_t sec) +{ return usduration(sec*uint64_t(1000000u)); } + +//!Utility that returns a duration from +//!a milliseconds count +inline usduration usduration_from_milliseconds(boost::uint64_t millisec) +{ return usduration(millisec*1000u); } + +//!Utility that returns a time_point in the future that is "msecs" +//!milliseconds in the future from now. +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 +{ + public: + typedef ustime time_point; + + static ustime universal_time() + { return ustime(universal_time_u64_us()); } +}; + +// duration_to_usduration + +template +inline usduration duration_to_usduration(const Duration &d, typename enable_if_ptime_duration::type* = 0) +{ + return usduration(static_cast(d.total_microseconds())); +} + +template +inline usduration duration_to_usduration(const Duration &d, typename enable_if_duration::type* = 0) +{ + const double factor = double(Duration::period::num)*1000000.0/double(Duration::period::den); + return usduration(static_cast(double(d.count())*factor)); +} + +inline usduration duration_to_usduration(const usduration &d) +{ + return d; +} + +// duration_to_ustime + +template +inline ustime duration_to_ustime(const Duration &d) +{ + return microsec_clock::universal_time() + (duration_to_usduration)(d); +} + + +} //namespace ipcdetail { + +#endif //#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) + +} //namespace interprocess { +} //namespace boost { + +#include + +#endif //BOOST_INTERPROCESS_TIMED_UTILS_HPP diff --git a/test/named_semaphore_test_helpers.hpp b/test/named_semaphore_test_helpers.hpp index fdac630..fd9ee10 100644 --- a/test/named_semaphore_test_helpers.hpp +++ b/test/named_semaphore_test_helpers.hpp @@ -20,7 +20,7 @@ #include "mutex_test_template.hpp" #include "get_process_id_name.hpp" #include -#include +#include #include diff --git a/test/semaphore_test_template.hpp b/test/semaphore_test_template.hpp index 2b6df3a..39152f9 100644 --- a/test/semaphore_test_template.hpp +++ b/test/semaphore_test_template.hpp @@ -23,15 +23,16 @@ #include #include +#include #include "named_creation_template.hpp" #include "mutex_test_template.hpp" -namespace boost { namespace interprocess { namespace test { - #include #include "named_creation_template.hpp" #include "mutex_test_template.hpp" +namespace boost { namespace interprocess { namespace test { + static const std::size_t SemCount = 1; static const std::size_t RecSemCount = 100; diff --git a/test/util.hpp b/test/util.hpp index 68b1b4e..12da848 100644 --- a/test/util.hpp +++ b/test/util.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #if defined(BOOST_CLANG) || (defined(BOOST_GCC) && (BOOST_GCC >= 40600)) #pragma GCC diagnostic push @@ -37,10 +38,10 @@ # endif #endif -#include #if BOOST_CXX_VERSION >= 201103L #define BOOST_CHRONO_HEADER_ONLY #include +#include #endif #include @@ -57,6 +58,9 @@ namespace boost { namespace interprocess { namespace test { +// ptime_delay_ms + ptime_ms + +#if BOOST_CXX_VERSION >= 201103L inline boost::posix_time::ptime ptime_delay_ms(unsigned msecs) { using namespace boost::posix_time; @@ -68,10 +72,19 @@ inline boost::posix_time::ptime ptime_delay_ms(unsigned msecs) inline boost::posix_time::time_duration ptime_ms(unsigned msecs) { using namespace boost::posix_time; - int count = static_cast(double(msecs)* - (double(time_duration::ticks_per_second())/double(1000.0))); + int count = static_cast(double(msecs) * + (double(time_duration::ticks_per_second()) / double(1000.0))); return time_duration(0, 0, 0, count); } +#else + inline ustime ptime_delay_ms(unsigned msecs) + { return ustime_delay_milliseconds(msecs); } + + inline usduration ptime_ms(unsigned msecs) + { return usduration_from_milliseconds(msecs); } +#endif + +// boost_systemclock_delay_ms + boost_systemclock_ms #if BOOST_CXX_VERSION >= 201103L inline boost::chrono::system_clock::time_point boost_systemclock_delay_ms(unsigned msecs) @@ -80,14 +93,15 @@ inline boost::posix_time::time_duration ptime_ms(unsigned msecs) inline boost::chrono::milliseconds boost_systemclock_ms(unsigned msecs) { return boost::chrono::milliseconds(msecs); } #else - inline boost::posix_time::ptime boost_systemclock_delay_ms(unsigned msecs) - { return ptime_delay_ms(msecs); } - - inline boost::posix_time::time_duration boost_systemclock_ms(unsigned msecs) - { return ptime_ms(msecs); } + inline ustime boost_systemclock_delay_ms(unsigned msecs) + { return ustime_delay_milliseconds(msecs); } + inline usduration boost_systemclock_ms(unsigned msecs) + { return usduration_from_milliseconds(msecs); } #endif +// std_systemclock_delay_ms + std_systemclock_ms + #if !defined(BOOST_NO_CXX11_HDR_CHRONO) //Use std chrono if available inline std::chrono::system_clock::time_point std_systemclock_delay_ms(unsigned msecs) @@ -103,15 +117,15 @@ inline boost::posix_time::time_duration ptime_ms(unsigned msecs) inline boost::chrono::milliseconds std_systemclock_ms(unsigned msecs) { return boost_systemclock_ms(msecs); } - #else - inline boost::posix_time::ptime std_systemclock_delay_ms(unsigned msecs) - { return ptime_delay_ms(msecs); } + inline ustime std_systemclock_delay_ms(unsigned msecs) + { return ustime_delay_milliseconds(msecs); } - inline boost::posix_time::time_duration std_systemclock_ms(unsigned msecs) - { return ptime_ms(msecs); } + inline usduration std_systemclock_ms(unsigned msecs) + { return usduration_from_milliseconds(msecs); } #endif +// thread_adapter + data template class thread_adapter