src/cxx_supportlib/vendor-modified/boost/thread/detail/thread.hpp in passenger-5.3.3 vs src/cxx_supportlib/vendor-modified/boost/thread/detail/thread.hpp in passenger-5.3.4
- old
+ new
@@ -34,10 +34,11 @@
#include <boost/type_traits/remove_reference.hpp>
#include <boost/io/ios_state.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/decay.hpp>
#include <boost/functional/hash.hpp>
+#include <boost/thread/detail/platform_time.hpp>
#ifdef BOOST_THREAD_USES_CHRONO
#include <boost/chrono/system_clocks.hpp>
#include <boost/chrono/ceil.hpp>
#endif
@@ -289,11 +290,11 @@
}
#else
template <class F>
explicit thread(F f
, typename disable_if_c<
- boost::thread_detail::is_rv<F>::value // todo ass a thread_detail::is_rv
+ boost::thread_detail::is_rv<F>::value // todo as a thread_detail::is_rv
//boost::thread_detail::is_convertible<F&,BOOST_THREAD_RV_REF(F)>::value
//|| is_same<typename decay<F>::type, thread>::value
, dummy* >::type=0
):
thread_info(make_thread_info(f))
@@ -452,115 +453,84 @@
{
thread_info.swap(x.thread_info);
}
class id;
-#ifdef BOOST_THREAD_PLATFORM_PTHREAD
- inline id get_id() const BOOST_NOEXCEPT;
-#else
id get_id() const BOOST_NOEXCEPT;
-#endif
-
bool joinable() const BOOST_NOEXCEPT;
private:
bool join_noexcept();
+ bool do_try_join_until_noexcept(detail::internal_platform_timepoint const &timeout, bool& res);
+ bool do_try_join_until(detail::internal_platform_timepoint const &timeout);
public:
- inline void join();
+ void join();
#ifdef BOOST_THREAD_USES_CHRONO
-#if defined(BOOST_THREAD_PLATFORM_WIN32)
- template <class Rep, class Period>
- bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
+ template <class Duration>
+ bool try_join_until(const chrono::time_point<detail::internal_chrono_clock, Duration>& t)
{
- chrono::milliseconds rel_time2= chrono::ceil<chrono::milliseconds>(rel_time);
- return do_try_join_until(rel_time2.count());
+ return do_try_join_until(boost::detail::internal_platform_timepoint(t));
}
-#else
- template <class Rep, class Period>
- bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
- {
- return try_join_until(chrono::steady_clock::now() + rel_time);
- }
-#endif
-#if defined(BOOST_THREAD_HAS_CONDATTR_SET_CLOCK_MONOTONIC) && defined(BOOST_THREAD_USEFIXES_TIMESPEC)
- typedef chrono::steady_clock my_clock_t;
-#else
- typedef chrono::system_clock my_clock_t;
-#endif
-
template <class Clock, class Duration>
bool try_join_until(const chrono::time_point<Clock, Duration>& t)
{
- using namespace chrono;
- bool joined= false;
- do {
- my_clock_t::time_point s_now = my_clock_t::now();
- typename Clock::duration d = ceil<nanoseconds>(t-Clock::now());
- if (d <= Clock::duration::zero()) return false; // in case the Clock::time_point t is already reached
- joined = try_join_until(s_now + d);
- } while (! joined);
+ typedef typename common_type<Duration, typename Clock::duration>::type common_duration;
+ common_duration d(t - Clock::now());
+ d = (std::min)(d, common_duration(chrono::milliseconds(BOOST_THREAD_POLL_INTERVAL_MILLISECONDS)));
+ while ( ! try_join_until(detail::internal_chrono_clock::now() + d) )
+ {
+ d = t - Clock::now();
+ if ( d <= common_duration::zero() ) return false; // timeout occurred
+ d = (std::min)(d, common_duration(chrono::milliseconds(BOOST_THREAD_POLL_INTERVAL_MILLISECONDS)));
+ }
return true;
}
- template <class Duration>
- bool try_join_until(const chrono::time_point<my_clock_t, Duration>& t)
- {
- using namespace chrono;
- typedef time_point<my_clock_t, nanoseconds> nano_sys_tmpt;
- return try_join_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
- }
-#endif
-#if defined(BOOST_THREAD_PLATFORM_WIN32)
- private:
- bool do_try_join_until_noexcept(uintmax_t milli, bool& res);
- inline bool do_try_join_until(uintmax_t milli);
- public:
- bool timed_join(const system_time& abs_time);
- //{
- // return do_try_join_until(get_milliseconds_until(wait_until));
- //}
-#ifdef BOOST_THREAD_USES_CHRONO
- bool try_join_until(const chrono::time_point<my_clock_t, chrono::nanoseconds>& tp)
+ template <class Rep, class Period>
+ bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
{
- chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
- return do_try_join_until(rel_time.count());
+ return try_join_until(chrono::steady_clock::now() + rel_time);
}
#endif
-
-
-#else
- private:
- bool do_try_join_until_noexcept(struct timespec const &timeout, bool& res);
- inline bool do_try_join_until(struct timespec const &timeout);
- public:
#if defined BOOST_THREAD_USES_DATETIME
bool timed_join(const system_time& abs_time)
{
- struct timespec const ts=detail::to_timespec(abs_time);
+ const detail::real_platform_timepoint ts(abs_time);
+#if defined BOOST_THREAD_INTERNAL_CLOCK_IS_MONO
+ detail::platform_duration d(ts - detail::real_platform_clock::now());
+ d = (std::min)(d, detail::platform_milliseconds(BOOST_THREAD_POLL_INTERVAL_MILLISECONDS));
+ while ( ! do_try_join_until(detail::internal_platform_clock::now() + d) )
+ {
+ d = ts - detail::real_platform_clock::now();
+ if ( d <= detail::platform_duration::zero() ) return false; // timeout occurred
+ d = (std::min)(d, detail::platform_milliseconds(BOOST_THREAD_POLL_INTERVAL_MILLISECONDS));
+ }
+ return true;
+#else
return do_try_join_until(ts);
- }
#endif
-#ifdef BOOST_THREAD_USES_CHRONO
- bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
- {
- using namespace chrono;
- nanoseconds d = tp.time_since_epoch();
- timespec ts = boost::detail::to_timespec(d);
- return do_try_join_until(ts);
}
-#endif
-#endif
- public:
-
-#if defined BOOST_THREAD_USES_DATETIME
template<typename TimeDuration>
- inline bool timed_join(TimeDuration const& rel_time)
+ bool timed_join(TimeDuration const& rel_time)
{
- return timed_join(get_system_time()+rel_time);
+ detail::platform_duration d(rel_time);
+#if defined(BOOST_THREAD_HAS_MONO_CLOCK) && !defined(BOOST_THREAD_INTERNAL_CLOCK_IS_MONO)
+ const detail::mono_platform_timepoint ts(detail::mono_platform_clock::now() + d);
+ d = (std::min)(d, detail::platform_milliseconds(BOOST_THREAD_POLL_INTERVAL_MILLISECONDS));
+ while ( ! do_try_join_until(detail::internal_platform_clock::now() + d) )
+ {
+ d = ts - detail::mono_platform_clock::now();
+ if ( d <= detail::platform_duration::zero() ) return false; // timeout occurred
+ d = (std::min)(d, detail::platform_milliseconds(BOOST_THREAD_POLL_INTERVAL_MILLISECONDS));
+ }
+ return true;
+#else
+ return do_try_join_until(detail::internal_platform_clock::now() + d);
+#endif
}
#endif
void detach();
static unsigned hardware_concurrency() BOOST_NOEXCEPT;
@@ -610,11 +580,11 @@
BOOST_THREAD_DCL_MOVABLE(thread)
namespace this_thread
{
#ifdef BOOST_THREAD_PLATFORM_PTHREAD
- inline thread::id get_id() BOOST_NOEXCEPT;
+ thread::id get_id() BOOST_NOEXCEPT;
#else
thread::id BOOST_THREAD_DECL get_id() BOOST_NOEXCEPT;
#endif
#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
@@ -741,11 +711,11 @@
#endif
#endif
};
#ifdef BOOST_THREAD_PLATFORM_PTHREAD
- thread::id thread::get_id() const BOOST_NOEXCEPT
+ inline thread::id thread::get_id() const BOOST_NOEXCEPT
{
#if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
return const_cast<thread*>(this)->native_handle();
#else
detail::thread_data_ptr const local_thread_info=(get_thread_info)();
@@ -764,23 +734,19 @@
return (thread_info?thread::id(thread_info->shared_from_this()):thread::id());
#endif
}
}
#endif
- void thread::join() {
+ inline void thread::join() {
if (this_thread::get_id() == get_id())
boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost thread: trying joining itself"));
BOOST_THREAD_VERIFY_PRECONDITION( join_noexcept(),
thread_resource_error(static_cast<int>(system::errc::invalid_argument), "boost thread: thread not joinable")
);
}
-#ifdef BOOST_THREAD_PLATFORM_PTHREAD
- bool thread::do_try_join_until(struct timespec const &timeout)
-#else
- bool thread::do_try_join_until(uintmax_t timeout)
-#endif
+ inline bool thread::do_try_join_until(detail::internal_platform_timepoint const &timeout)
{
if (this_thread::get_id() == get_id())
boost::throw_exception(thread_resource_error(static_cast<int>(system::errc::resource_deadlock_would_occur), "boost thread: trying joining itself"));
bool res;
if (do_try_join_until_noexcept(timeout, res))