diff --git a/include/boost/fiber/bounded_queue.hpp b/include/boost/fiber/bounded_queue.hpp index 92377523..b038d5ce 100644 --- a/include/boost/fiber/bounded_queue.hpp +++ b/include/boost/fiber/bounded_queue.hpp @@ -243,15 +243,15 @@ public: template< typename Rep, typename Period > queue_op_status push_wait_for( value_type const& va, chrono::duration< Rep, Period > const& timeout_duration) - { return push_wait_until( va, clock_type::now() + timeout_duration); } + { return push_wait_until( va, chrono::high_resolution_clock::now() + timeout_duration); } template< typename Rep, typename Period > queue_op_status push_wait_for( BOOST_RV_REF( value_type) va, chrono::duration< Rep, Period > const& timeout_duration) - { return push_wait_until( boost::move( va), clock_type::now() + timeout_duration); } + { return push_wait_until( boost::move( va), chrono::high_resolution_clock::now() + timeout_duration); } queue_op_status push_wait_until( value_type const& va, - clock_type::time_point const& timeout_time) + chrono::high_resolution_clock::time_point const& timeout_time) { typename node_type::ptr new_node( new node_type( va) ); boost::unique_lock< mutex > lk( mtx_); @@ -278,7 +278,7 @@ public: } queue_op_status push_wait_until( BOOST_RV_REF( value_type) va, - clock_type::time_point const& timeout_time) + chrono::high_resolution_clock::time_point const& timeout_time) { typename node_type::ptr new_node( new node_type( boost::move( va) ) ); boost::unique_lock< mutex > lk( mtx_); @@ -304,6 +304,22 @@ public: } } + template< typename ClockType > + queue_op_status push_wait_until( value_type const& va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return push_wait_until( va, timeout_time); + } + + template< typename ClockType > + queue_op_status push_wait_until( BOOST_RV_REF( value_type) va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return push_wait_until( boost::move( va), timeout_time); + } + queue_op_status try_push( value_type const& va) { typename node_type::ptr new_node( new node_type( va) ); @@ -413,10 +429,10 @@ public: template< typename Rep, typename Period > queue_op_status pop_wait_for( value_type & va, chrono::duration< Rep, Period > const& timeout_duration) - { return pop_wait_until( va, clock_type::now() + timeout_duration); } + { return pop_wait_until( va, chrono::high_resolution_clock::now() + timeout_duration); } queue_op_status pop_wait_until( value_type & va, - clock_type::time_point const& timeout_time) + chrono::high_resolution_clock::time_point const& timeout_time) { boost::unique_lock< mutex > lk( mtx_); @@ -451,6 +467,14 @@ public: } } + template< typename ClockType > + queue_op_status pop_wait_until( value_type & va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return pop_wait_until( va, timeout_time); + } + queue_op_status try_pop( value_type & va) { boost::unique_lock< mutex > lk( mtx_); @@ -622,10 +646,10 @@ public: template< typename Rep, typename Period > queue_op_status push_wait_for( value_type va, chrono::duration< Rep, Period > const& timeout_duration) - { return push_wait_until( va, clock_type::now() + timeout_duration); } + { return push_wait_until( va, chrono::high_resolution_clock::now() + timeout_duration); } queue_op_status push_wait_until( value_type va, - clock_type::time_point const& timeout_time) + chrono::high_resolution_clock::time_point const& timeout_time) { typename node_type::ptr new_node( new node_type( va) ); boost::unique_lock< mutex > lk( mtx_); @@ -651,6 +675,14 @@ public: } } + template< typename ClockType > + queue_op_status push_wait_until( value_type va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return push_wait_until( va, timeout_time); + } + queue_op_status try_push( value_type va) { typename node_type::ptr new_node( new node_type( va) ); @@ -760,10 +792,10 @@ public: template< typename Rep, typename Period > queue_op_status pop_wait_for( value_type va, chrono::duration< Rep, Period > const& timeout_duration) - { return pop_wait_until( va, clock_type::now() + timeout_duration); } + { return pop_wait_until( va, chrono::high_resolution_clock::now() + timeout_duration); } queue_op_status pop_wait_until( value_type va, - clock_type::time_point const& timeout_time) + chrono::high_resolution_clock::time_point const& timeout_time) { boost::unique_lock< mutex > lk( mtx_); @@ -798,6 +830,14 @@ public: } } + template< typename ClockType > + queue_op_status pop_wait_until( value_type va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return pop_wait_until( va, timeout_time); + } + queue_op_status try_pop( value_type va) { boost::unique_lock< mutex > lk( mtx_); diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index 2f8b4d2d..b6f94db6 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -139,7 +139,7 @@ public: } template< typename LockType > - cv_status wait_until( LockType & lt, clock_type::time_point const& timeout_time) + cv_status wait_until( LockType & lt, chrono::high_resolution_clock::time_point const& timeout_time) { cv_status status = cv_status::no_timeout; @@ -201,7 +201,7 @@ public: while ( ! n->is_ready() ) { // check timepoint - if ( ! ( clock_type::now() < timeout_time) ) + if ( ! ( chrono::high_resolution_clock::now() < timeout_time) ) { // timeout happend before notified // lock spinlock @@ -234,9 +234,28 @@ public: return status; } - template< typename LockType, typename Pred > - bool wait_until( LockType & lt, clock_type::time_point const& timeout_time, Pred pred) + template< typename LockType, typename ClockType > + cv_status wait_until( LockType & lt, typename ClockType::time_point const& timeout_time_) { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( lt, timeout_time); + } + + template< typename LockType, typename Pred > + bool wait_until( LockType & lt, chrono::high_resolution_clock::time_point const& timeout_time, Pred pred) + { + while ( ! pred() ) + { + if ( cv_status::timeout == wait_until( lt, timeout_time) ) + return pred(); + } + return true; + } + + template< typename LockType, typename ClockType, typename Pred > + bool wait_until( LockType & lt, typename ClockType::time_point const& timeout_time_, Pred pred) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); while ( ! pred() ) { if ( cv_status::timeout == wait_until( lt, timeout_time) ) @@ -247,7 +266,7 @@ public: template< typename LockType, typename Rep, typename Period > cv_status wait_for( LockType & lt, chrono::duration< Rep, Period > const& timeout_duration) - { return wait_until( lt, clock_type::now() + timeout_duration); } + { return wait_until( lt, chrono::high_resolution_clock::now() + timeout_duration); } template< typename LockType, typename Rep, typename Period, typename Pred > bool wait_for( LockType & lt, chrono::duration< Rep, Period > const& timeout_duration, Pred pred) diff --git a/include/boost/fiber/detail/config.hpp b/include/boost/fiber/detail/config.hpp index 14258990..a7f71a81 100644 --- a/include/boost/fiber/detail/config.hpp +++ b/include/boost/fiber/detail/config.hpp @@ -7,7 +7,6 @@ #ifndef BOOST_FIBERS_DETAIL_CONFIG_H #define BOOST_FIBERS_DETAIL_CONFIG_H -#include #include #include @@ -43,13 +42,4 @@ # define BOOST_FIBERS_SEGMENTS 10 #endif -namespace boost { -namespace fibers { -#if defined(BOOST_HAS_CLOCK_STEADY) - typedef boost::chrono::steady_clock clock_type; -#else - typedef boost::chrono::system_clock clock_type; -#endif -}} - #endif // BOOST_FIBERS_DETAIL_CONFIG_H diff --git a/include/boost/fiber/detail/worker_fiber.hpp b/include/boost/fiber/detail/worker_fiber.hpp index 9ef977a4..2a4010ad 100644 --- a/include/boost/fiber/detail/worker_fiber.hpp +++ b/include/boost/fiber/detail/worker_fiber.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -89,7 +90,7 @@ private: atomic< std::size_t > use_count_; fss_data_t fss_data_; worker_fiber * nxt_; - clock_type::time_point tp_; + chrono::high_resolution_clock::time_point tp_; coro_t::yield_type * callee_; coro_t::call_type caller_; atomic< state_t > state_; @@ -218,14 +219,14 @@ public: void next_reset() BOOST_NOEXCEPT { nxt_ = 0; } - clock_type::time_point const& time_point() const BOOST_NOEXCEPT + chrono::high_resolution_clock::time_point const& time_point() const BOOST_NOEXCEPT { return tp_; } - void time_point( clock_type::time_point const& tp) + void time_point( chrono::high_resolution_clock::time_point const& tp) { tp_ = tp; } void time_point_reset() - { tp_ = (clock_type::time_point::max)(); } + { tp_ = (chrono::high_resolution_clock::time_point::max)(); } void release(); diff --git a/include/boost/fiber/fiber_manager.hpp b/include/boost/fiber/fiber_manager.hpp index 7105d567..e28db9d4 100644 --- a/include/boost/fiber/fiber_manager.hpp +++ b/include/boost/fiber/fiber_manager.hpp @@ -7,6 +7,7 @@ #define BOOST_FIBERS_FIBER_MANAGER_H #include +#include #include #include #include @@ -54,7 +55,7 @@ struct fiber_manager : private noncopyable sched_algorithm * sched_algo_; wqueue_t wqueue_; - clock_type::duration wait_interval_; + chrono::high_resolution_clock::duration wait_interval_; detail::worker_fiber * active_fiber_; }; @@ -66,12 +67,12 @@ void fm_spawn( detail::worker_fiber *); void fm_priority( detail::worker_fiber *, int) BOOST_NOEXCEPT; -void fm_wait_interval( clock_type::duration const&) BOOST_NOEXCEPT; +void fm_wait_interval( chrono::high_resolution_clock::duration const&) BOOST_NOEXCEPT; template< typename Rep, typename Period > void fm_wait_interval( chrono::duration< Rep, Period > const& wait_interval) BOOST_NOEXCEPT { fm_wait_interval( wait_interval); } -clock_type::duration fm_wait_interval() BOOST_NOEXCEPT; +chrono::high_resolution_clock::duration fm_wait_interval() BOOST_NOEXCEPT; void fm_join( detail::worker_fiber *); @@ -80,18 +81,18 @@ detail::worker_fiber * fm_active() BOOST_NOEXCEPT; void fm_run(); void fm_wait( unique_lock< detail::spinlock > &); -bool fm_wait_until( clock_type::time_point const&, +bool fm_wait_until( chrono::high_resolution_clock::time_point const&, unique_lock< detail::spinlock > &); template< typename Rep, typename Period > bool fm_wait_for( chrono::duration< Rep, Period > const& timeout_duration, unique_lock< detail::spinlock > & lk) { - return wait_until( clock_type::now() + timeout_duration, lk); + return wait_until( chrono::high_resolution_clock::now() + timeout_duration, lk); } void fm_yield(); -clock_type::time_point fm_next_wakeup(); +chrono::high_resolution_clock::time_point fm_next_wakeup(); void fm_migrate( detail::worker_fiber *); diff --git a/include/boost/fiber/future/detail/shared_state.hpp b/include/boost/fiber/future/detail/shared_state.hpp index 6306eae3..8ca58119 100644 --- a/include/boost/fiber/future/detail/shared_state.hpp +++ b/include/boost/fiber/future/detail/shared_state.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -145,7 +146,7 @@ private: } future_status wait_until_( unique_lock< mutex > & lk, - clock_type::time_point const& timeout_time) const + chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout while ( ! ready_) @@ -263,7 +264,7 @@ public: return wait_for_( lk, timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -372,7 +373,7 @@ private: } future_status wait_until_( unique_lock< mutex > & lk, - clock_type::time_point const& timeout_time) const + chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout while ( ! ready_) @@ -466,7 +467,7 @@ public: return wait_for_( lk, timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -572,7 +573,7 @@ private: } future_status wait_until_( unique_lock< mutex > & lk, - clock_type::time_point const& timeout_time) const + chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout while ( ! ready_) @@ -665,7 +666,7 @@ public: return wait_for_( lk, timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call diff --git a/include/boost/fiber/future/future.hpp b/include/boost/fiber/future/future.hpp index e42b360f..1ca3586e 100644 --- a/include/boost/fiber/future/future.hpp +++ b/include/boost/fiber/future/future.hpp @@ -7,6 +7,7 @@ #ifndef BOOST_FIBERS_FUTURE_HPP #define BOOST_FIBERS_FUTURE_HPP +#include #include #include #include @@ -171,7 +172,7 @@ public: return state_->wait_for( timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -180,6 +181,14 @@ public: future_uninitialized() ); return state_->wait_until( timeout_time); } + + template< typename ClockType > + future_status wait_until( typename ClockType::time_point const& timeout_time_) const + { + chrono::high_resolution_clock::time_point timeout_time( + chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( timeout_time); + } }; template< typename R > @@ -321,7 +330,7 @@ public: return state_->wait_for( timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -330,6 +339,14 @@ public: future_uninitialized() ); return state_->wait_until( timeout_time); } + + template< typename ClockType > + future_status wait_until( typename ClockType::time_point const& timeout_time_) const + { + chrono::high_resolution_clock::time_point timeout_time( + chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( timeout_time); + } }; template<> @@ -471,7 +488,7 @@ public: return state_->wait_for( timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -480,6 +497,14 @@ public: future_uninitialized() ); return state_->wait_until( timeout_time); } + + template< typename ClockType > + future_status wait_until( typename ClockType::time_point const& timeout_time_) const + { + chrono::high_resolution_clock::time_point timeout_time( + chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( timeout_time); + } }; template< typename R > @@ -659,7 +684,7 @@ public: return state_->wait_for( timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -668,6 +693,14 @@ public: future_uninitialized() ); return state_->wait_until( timeout_time); } + + template< typename ClockType > + future_status wait_until( typename ClockType::time_point const& timeout_time_) const + { + chrono::high_resolution_clock::time_point timeout_time( + chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( timeout_time); + } }; template< typename R > @@ -841,7 +874,7 @@ public: return state_->wait_for( timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -850,6 +883,14 @@ public: future_uninitialized() ); return state_->wait_until( timeout_time); } + + template< typename ClockType > + future_status wait_until( typename ClockType::time_point const& timeout_time_) const + { + chrono::high_resolution_clock::time_point timeout_time( + chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( timeout_time); + } }; template<> @@ -1029,7 +1070,7 @@ public: return state_->wait_for( timeout_duration); } - future_status wait_until( clock_type::time_point const& timeout_time) const + future_status wait_until( chrono::high_resolution_clock::time_point const& timeout_time) const { //TODO: blocks until the result becomes available or timeout // valid() == true after the call @@ -1038,6 +1079,14 @@ public: future_uninitialized() ); return state_->wait_until( timeout_time); } + + template< typename ClockType > + future_status wait_until( typename ClockType::time_point const& timeout_time_) const + { + chrono::high_resolution_clock::time_point timeout_time( + chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return wait_until( timeout_time); + } }; template< typename R > diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index 1fdc06ec..e4ef3d6e 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -7,6 +7,8 @@ #define BOOST_THIS_FIBER_OPERATIONS_H #include +#include +#include #include #include @@ -40,7 +42,7 @@ void yield() } inline -void sleep_until( fibers::clock_type::time_point const& sleep_time) +void sleep_until( chrono::high_resolution_clock::time_point const& sleep_time) { if ( 0 != fibers::fm_active() ) { @@ -53,14 +55,21 @@ void sleep_until( fibers::clock_type::time_point const& sleep_time) } else { - while ( fibers::clock_type::now() <= sleep_time) + while ( chrono::high_resolution_clock::now() <= sleep_time) fibers::fm_run(); } } +template< typename ClockType > +void sleep_until( typename ClockType::time_point const& sleep_time_) +{ + chrono::high_resolution_clock::time_point sleep_time( chrono::high_resolution_clock::now() + ( sleep_time_ - ClockType::now() ) ); + sleep_until( sleep_time); +} + template< typename Rep, typename Period > void sleep_for( chrono::duration< Rep, Period > const& timeout_duration) -{ sleep_until( fibers::clock_type::now() + timeout_duration); } +{ sleep_until( chrono::high_resolution_clock::now() + timeout_duration); } inline bool thread_affinity() BOOST_NOEXCEPT diff --git a/include/boost/fiber/recursive_timed_mutex.hpp b/include/boost/fiber/recursive_timed_mutex.hpp index 9e08bcca..6ddf899e 100644 --- a/include/boost/fiber/recursive_timed_mutex.hpp +++ b/include/boost/fiber/recursive_timed_mutex.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -58,11 +59,18 @@ public: bool try_lock(); - bool try_lock_until( clock_type::time_point const& timeout_time); + bool try_lock_until( chrono::high_resolution_clock::time_point const& timeout_time); + + template< typename ClockType > + bool try_lock_until( typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return try_lock_until( timeout_time); + } template< typename Rep, typename Period > bool try_lock_for( chrono::duration< Rep, Period > const& timeout_duration) - { return try_lock_until( clock_type::now() + timeout_duration); } + { return try_lock_until( chrono::high_resolution_clock::now() + timeout_duration); } void unlock(); }; diff --git a/include/boost/fiber/timed_mutex.hpp b/include/boost/fiber/timed_mutex.hpp index 45eec9c4..dc36473e 100644 --- a/include/boost/fiber/timed_mutex.hpp +++ b/include/boost/fiber/timed_mutex.hpp @@ -9,6 +9,7 @@ #include +#include #include #include @@ -54,11 +55,18 @@ public: bool try_lock(); - bool try_lock_until( clock_type::time_point const& timeout_time); + bool try_lock_until( chrono::high_resolution_clock::time_point const& timeout_time); + + template< typename ClockType > + bool try_lock_until( typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock::time_point timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return try_lock_until( timeout_time); + } template< typename Rep, typename Period > bool try_lock_for( chrono::duration< Rep, Period > const& timeout_duration) - { return try_lock_until( clock_type::now() + timeout_duration); } + { return try_lock_until( chrono::high_resolution_clock::now() + timeout_duration); } void unlock(); }; diff --git a/include/boost/fiber/unbounded_queue.hpp b/include/boost/fiber/unbounded_queue.hpp index 8a1c27d7..3029d038 100644 --- a/include/boost/fiber/unbounded_queue.hpp +++ b/include/boost/fiber/unbounded_queue.hpp @@ -234,10 +234,10 @@ public: template< typename Rep, typename Period > queue_op_status pop_wait_for( value_type & va, chrono::duration< Rep, Period > const& timeout_duration) - { return pop_wait_until( va, clock_type::now() + timeout_duration); } + { return pop_wait_until( va, chrono::high_resolution_clock::now() + timeout_duration); } queue_op_status pop_wait_until( value_type & va, - clock_type::time_point const& timeout_time) + chrono::high_resolution_clock::time_point const& timeout_time) { boost::unique_lock< mutex > lk( mtx_); @@ -263,6 +263,14 @@ public: } } + template< typename ClockType > + queue_op_status pop_wait_until( value_type & va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return pop_wait_until( va, timeout_time); + } + queue_op_status try_pop( value_type & va) { boost::unique_lock< mutex > lk( mtx_); @@ -421,9 +429,9 @@ public: template< typename Rep, typename Period > queue_op_status pop_wait_for( value_type va, chrono::duration< Rep, Period > const& timeout_duration) - { return pop_wait_until( va, clock_type::now() + timeout_duration); } + { return pop_wait_until( va, chrono::high_resolution_clock::now() + timeout_duration); } - queue_op_status pop_wait_until( value_type va, clock_type::time_point const& timeout_time) + queue_op_status pop_wait_until( value_type va, chrono::high_resolution_clock::time_point const& timeout_time) { boost::unique_lock< mutex > lk( mtx_); @@ -449,6 +457,14 @@ public: } } + template< typename ClockType > + queue_op_status pop_wait_until( value_type va, + typename ClockType::time_point const& timeout_time_) + { + chrono::high_resolution_clock timeout_time( chrono::high_resolution_clock::now() + ( timeout_time_ - ClockType::now() ) ); + return pop_wait_until( va, timeout_time); + } + queue_op_status try_pop( value_type va) { boost::unique_lock< mutex > lk( mtx_); diff --git a/performance/clock.hpp b/performance/clock.hpp index 6103951f..5ca3cff7 100644 --- a/performance/clock.hpp +++ b/performance/clock.hpp @@ -17,15 +17,15 @@ #include typedef boost::chrono::high_resolution_clock clock_type; -typedef clock_type::duration duration_type; -typedef clock_type::time_point time_point_type; +typedef chronoduration duration_type; +typedef chronotime_point time_point_type; struct clock_overhead { boost::uint64_t operator()() { - time_point_type start( clock_type::now() ); - return ( clock_type::now() - start).count(); + time_point_type start( chrononow() ); + return ( chrononow() - start).count(); } }; diff --git a/src/detail/worker_fiber.cpp b/src/detail/worker_fiber.cpp index 8e0573a9..c7fa9f5f 100644 --- a/src/detail/worker_fiber.cpp +++ b/src/detail/worker_fiber.cpp @@ -30,7 +30,7 @@ worker_fiber::worker_fiber( coro_t::yield_type * callee) : use_count_( 1), // allocated on stack fss_data_(), nxt_( 0), - tp_( (clock_type::time_point::max)() ), + tp_( (chrono::high_resolution_clock::time_point::max)() ), callee_( callee), caller_(), state_( READY), diff --git a/src/fiber_manager.cpp b/src/fiber_manager.cpp index a777909f..5080884d 100644 --- a/src/fiber_manager.cpp +++ b/src/fiber_manager.cpp @@ -37,7 +37,7 @@ bool fetch_ready( detail::worker_fiber * f) // set fiber to state_ready if dead-line was reached // set fiber to state_ready if interruption was requested - if ( f->time_point() <= clock_type::now() || f->interruption_requested() ) + if ( f->time_point() <= chrono::high_resolution_clock::now() || f->interruption_requested() ) f->set_ready(); return f->is_ready(); } @@ -100,20 +100,20 @@ void fm_set_sched_algo( sched_algorithm * algo) fm->def_algo_.reset(); } -clock_type::time_point fm_next_wakeup() +chrono::high_resolution_clock::time_point fm_next_wakeup() { fiber_manager * fm = detail::scheduler::instance(); BOOST_ASSERT( 0 != fm); if ( fm->wqueue_.empty() ) - return clock_type::now() + fm->wait_interval_; + return chrono::high_resolution_clock::now() + fm->wait_interval_; else { //FIXME: search for the closest time_point to now() in waiting-queue - clock_type::time_point wakeup( fm->wqueue_.top()->time_point() ); - if ( (clock_type::time_point::max)() == wakeup) - return clock_type::now() + fm->wait_interval_; + chrono::high_resolution_clock::time_point wakeup( fm->wqueue_.top()->time_point() ); + if ( (chrono::high_resolution_clock::time_point::max)() == wakeup) + return chrono::high_resolution_clock::now() + fm->wait_interval_; return wakeup; } } @@ -140,7 +140,7 @@ void fm_priority( detail::worker_fiber * f, fm->sched_algo_->priority( f, prio); } -void fm_wait_interval( clock_type::duration const& wait_interval) BOOST_NOEXCEPT +void fm_wait_interval( chrono::high_resolution_clock::duration const& wait_interval) BOOST_NOEXCEPT { fiber_manager * fm = detail::scheduler::instance(); @@ -149,7 +149,7 @@ void fm_wait_interval( clock_type::duration const& wait_interval) BOOST_NOEXCEPT fm->wait_interval_ = wait_interval; } -clock_type::duration fm_wait_interval() BOOST_NOEXCEPT +chrono::high_resolution_clock::duration fm_wait_interval() BOOST_NOEXCEPT { fiber_manager * fm = detail::scheduler::instance(); @@ -184,7 +184,7 @@ void fm_run() { // no fibers ready to run; the thread should sleep // until earliest fiber is scheduled to run - clock_type::time_point wakeup( fm_next_wakeup() ); + chrono::high_resolution_clock::time_point wakeup( fm_next_wakeup() ); this_thread::sleep_until( wakeup); } } @@ -192,10 +192,10 @@ void fm_run() void fm_wait( unique_lock< detail::spinlock > & lk) { - fm_wait_until( clock_type::time_point( (clock_type::duration::max)() ), lk); + fm_wait_until( chrono::high_resolution_clock::time_point( (chrono::high_resolution_clock::duration::max)() ), lk); } -bool fm_wait_until( clock_type::time_point const& timeout_time, +bool fm_wait_until( chrono::high_resolution_clock::time_point const& timeout_time, unique_lock< detail::spinlock > & lk) { fiber_manager * fm = detail::scheduler::instance(); @@ -204,7 +204,7 @@ bool fm_wait_until( clock_type::time_point const& timeout_time, BOOST_ASSERT( 0 != fm->active_fiber_); BOOST_ASSERT( fm->active_fiber_->is_running() ); - clock_type::time_point start( clock_type::now() ); + chrono::high_resolution_clock::time_point start( chrono::high_resolution_clock::now() ); // set active-fiber to state_waiting fm->active_fiber_->set_waiting(); @@ -216,7 +216,7 @@ bool fm_wait_until( clock_type::time_point const& timeout_time, // suspend active-fiber fm->active_fiber_->suspend(); - return clock_type::now() < timeout_time; + return chrono::high_resolution_clock::now() < timeout_time; } void fm_yield() diff --git a/src/recursive_timed_mutex.cpp b/src/recursive_timed_mutex.cpp index c1b31784..cdc8f78a 100644 --- a/src/recursive_timed_mutex.cpp +++ b/src/recursive_timed_mutex.cpp @@ -114,7 +114,7 @@ recursive_timed_mutex::try_lock() } bool -recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) +recursive_timed_mutex::try_lock_until( chrono::high_resolution_clock::time_point const& timeout_time) { detail::fiber_base * n( fm_active() ); if ( n) @@ -123,7 +123,7 @@ recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_tim { unique_lock< detail::spinlock > lk( splk_); - if ( clock_type::now() > timeout_time) + if ( chrono::high_resolution_clock::now() > timeout_time) return false; if ( lock_if_unlocked_() ) return true; @@ -154,7 +154,7 @@ recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_tim { unique_lock< detail::spinlock > lk( splk_); - if ( clock_type::now() > timeout_time) + if ( chrono::high_resolution_clock::now() > timeout_time) return false; if ( lock_if_unlocked_() ) return true; @@ -167,7 +167,7 @@ recursive_timed_mutex::try_lock_until( clock_type::time_point const& timeout_tim // wait until main-fiber gets notified while ( ! n->is_ready() ) { - if ( clock_type::now() > timeout_time) + if ( chrono::high_resolution_clock::now() > timeout_time) { lk.lock(); // remove fiber from waiting-list diff --git a/src/timed_mutex.cpp b/src/timed_mutex.cpp index d4071111..51eea444 100644 --- a/src/timed_mutex.cpp +++ b/src/timed_mutex.cpp @@ -103,7 +103,7 @@ timed_mutex::try_lock() } bool -timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) +timed_mutex::try_lock_until( chrono::high_resolution_clock::time_point const& timeout_time) { detail::fiber_base * n( fm_active() ); if ( n) @@ -112,7 +112,7 @@ timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) { unique_lock< detail::spinlock > lk( splk_); - if ( clock_type::now() > timeout_time) + if ( chrono::high_resolution_clock::now() > timeout_time) return false; if ( lock_if_unlocked_() ) return true; @@ -143,7 +143,7 @@ timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) { unique_lock< detail::spinlock > lk( splk_); - if ( clock_type::now() > timeout_time) + if ( chrono::high_resolution_clock::now() > timeout_time) return false; if ( lock_if_unlocked_() ) return true; @@ -156,7 +156,7 @@ timed_mutex::try_lock_until( clock_type::time_point const& timeout_time) // wait until main-fiber gets notified while ( ! n->is_ready() ) { - if ( clock_type::now() > timeout_time) + if ( chrono::high_resolution_clock::now() > timeout_time) { lk.lock(); // remove fiber from waiting-list diff --git a/test/test_condition.cpp b/test/test_condition.cpp index e236844e..92e2e363 100644 --- a/test/test_condition.cpp +++ b/test/test_condition.cpp @@ -243,12 +243,12 @@ void fn2( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) BOOST_CHECK(test2 == 0); test1 = 1; cv.notify_one(); - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); - boost::fibers::clock_type::time_point t = t0 + ms(250); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); + boost::chrono::high_resolution_clock::time_point t = t0 + ms(250); int count=0; while (test2 == 0 && cv.wait_until(lk, t) == boost::fibers::cv_status::no_timeout) count++; - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); if (runs == 0) { BOOST_CHECK(t1 - t0 < ms(250)); @@ -281,10 +281,10 @@ void fn3( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) BOOST_CHECK(test2 == 0); test1 = 1; cv.notify_one(); - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); - boost::fibers::clock_type::time_point t = t0 + ms(250); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); + boost::chrono::high_resolution_clock::time_point t = t0 + ms(250); bool r = cv.wait_until(lk, t, Pred(test2)); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); if (runs == 0) { BOOST_CHECK(t1 - t0 < ms(250)); @@ -306,11 +306,11 @@ void fn4( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) BOOST_CHECK(test2 == 0); test1 = 1; cv.notify_one(); - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); int count=0; while (test2 == 0 && cv.wait_for(lk, ms(250)) == boost::fibers::cv_status::no_timeout) count++; - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); if (runs == 0) { BOOST_CHECK(t1 - t0 < ms(250)); @@ -330,11 +330,11 @@ void fn5( boost::fibers::mutex & m, boost::fibers::condition_variable & cv) BOOST_CHECK(test2 == 0); test1 = 1; cv.notify_one(); - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); int count=0; cv.wait_for(lk, ms(250), Pred(test2)); count++; - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); if (runs == 0) { BOOST_CHECK(t1 - t0 < ms(250+1000)); diff --git a/test/test_mutex.cpp b/test/test_mutex.cpp index 75429177..8f7b801f 100644 --- a/test/test_mutex.cpp +++ b/test/test_mutex.cpp @@ -49,9 +49,9 @@ void fn2( M & mtx) void fn3( boost::fibers::timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); m.lock(); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(2500000)+ms(1000)); // within 2.5 ms @@ -59,9 +59,9 @@ void fn3( boost::fibers::timed_mutex & m) void fn4( boost::fibers::timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); while ( ! m.try_lock() ); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(50000000)+ms(2000)); // within 50 ms @@ -69,9 +69,9 @@ void fn4( boost::fibers::timed_mutex & m) void fn5( boost::fibers::timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK( m.try_lock_for(ms(300)+ms(2000)) == true); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(2000)); // within 5 ms @@ -79,18 +79,18 @@ void fn5( boost::fibers::timed_mutex & m) void fn6( boost::fibers::timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK(m.try_lock_for(ms(250)) == false); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(1000)); // within 5 ms } void fn7( boost::fibers::timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); - BOOST_CHECK(m.try_lock_until(boost::fibers::clock_type::now() + ms(300) + ms(1000)) == true); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); + BOOST_CHECK(m.try_lock_until(boost::chrono::high_resolution_clock::now() + ms(300) + ms(1000)) == true); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(1000)); // within 5ms @@ -98,18 +98,18 @@ void fn7( boost::fibers::timed_mutex & m) void fn8( boost::fibers::timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); - BOOST_CHECK(m.try_lock_until(boost::fibers::clock_type::now() + ms(250)) == false); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); + BOOST_CHECK(m.try_lock_until(boost::chrono::high_resolution_clock::now() + ms(250)) == false); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(1000)); // within 5ms } void fn9( boost::fibers::recursive_timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); m.lock(); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.lock(); m.unlock(); m.unlock(); @@ -119,9 +119,9 @@ void fn9( boost::fibers::recursive_timed_mutex & m) void fn10( boost::fibers::recursive_timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); while (!m.try_lock()) ; - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK(m.try_lock()); m.unlock(); m.unlock(); @@ -131,9 +131,9 @@ void fn10( boost::fibers::recursive_timed_mutex & m) void fn11( boost::fibers::recursive_timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK(m.try_lock_for(ms(300)+ms(1000)) == true); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK(m.try_lock()); m.unlock(); m.unlock(); @@ -143,18 +143,18 @@ void fn11( boost::fibers::recursive_timed_mutex & m) void fn12( boost::fibers::recursive_timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK(m.try_lock_for(ms(250)) == false); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(1000)); // within 5 ms } void fn13( boost::fibers::recursive_timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); - BOOST_CHECK(m.try_lock_until(boost::fibers::clock_type::now() + ms(300) + ms(1000)) == true); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); + BOOST_CHECK(m.try_lock_until(boost::chrono::high_resolution_clock::now() + ms(300) + ms(1000)) == true); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(1000)); // within 5 ms @@ -162,18 +162,18 @@ void fn13( boost::fibers::recursive_timed_mutex & m) void fn14( boost::fibers::recursive_timed_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); - BOOST_CHECK(m.try_lock_until(boost::fibers::clock_type::now() + ms(250)) == false); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); + BOOST_CHECK(m.try_lock_until(boost::chrono::high_resolution_clock::now() + ms(250)) == false); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(5000000)+ms(1000)); // within 5 ms } void fn15( boost::fibers::recursive_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); m.lock(); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.lock(); m.unlock(); m.unlock(); @@ -183,9 +183,9 @@ void fn15( boost::fibers::recursive_mutex & m) void fn16( boost::fibers::recursive_mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); while (!m.try_lock()); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); BOOST_CHECK(m.try_lock()); m.unlock(); m.unlock(); @@ -195,9 +195,9 @@ void fn16( boost::fibers::recursive_mutex & m) void fn17( boost::fibers::mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); m.lock(); - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(2500000)+ms(1000)); // within 2.5 ms @@ -205,9 +205,9 @@ void fn17( boost::fibers::mutex & m) void fn18( boost::fibers::mutex & m) { - boost::fibers::clock_type::time_point t0 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now(); while (!m.try_lock()) ; - boost::fibers::clock_type::time_point t1 = boost::fibers::clock_type::now(); + boost::chrono::high_resolution_clock::time_point t1 = boost::chrono::high_resolution_clock::now(); m.unlock(); ns d = t1 - t0 - ms(250); BOOST_CHECK(d < ns(50000000)+ms(1000)); // within 50 ms