From 9938799b6d3d06c444e3fb03ca6a780e3b6a5f8c Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Fri, 19 Jan 2018 11:47:46 -0800 Subject: [PATCH] Handle max deadlines in Futex Summary: [Folly] Handle max deadlines in `Futex`. Some of the synchronization code internally treats deadlines which are equivalent to `time_point::max()` for the same clock as a sentinel value indicating a deadline at infinity, or equivalently the lack of a deadline. Care must be taken when converting between clocks to translate a deadline at infinity for one clock to the deadline at infinity for the other clock. Reviewed By: nbronson Differential Revision: D6720021 fbshipit-source-id: cfc230dd2d8db55297385a4afcb6d87ae4221840 --- folly/detail/Futex.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/folly/detail/Futex.h b/folly/detail/Futex.h index de0c78f9..aadddd03 100644 --- a/folly/detail/Futex.h +++ b/folly/detail/Futex.h @@ -73,7 +73,9 @@ struct Futex : Atom { std::chrono::steady_clock, std::chrono::system_clock>::type; auto const converted = time_point_conv(deadline); - return futexWaitImpl(expected, converted, waitMask); + return converted == Target::time_point::max() + ? futexWaitImpl(expected, nullptr, nullptr, waitMask) + : futexWaitImpl(expected, converted, waitMask); } /** Wakens up to count waiters where (waitMask & wakeMask) != @@ -95,9 +97,12 @@ struct Futex : Atom { static typename TargetClock::time_point time_point_conv( std::chrono::time_point const& time) { using std::chrono::duration_cast; + using TimePoint = std::chrono::time_point; using TargetDuration = typename TargetClock::duration; using TargetTimePoint = typename TargetClock::time_point; - if (std::is_same::value) { + if (time == TimePoint::max()) { + return TargetTimePoint::max(); + } else if (std::is_same::value) { // in place of time_point_cast, which cannot compile without if-constexpr auto const delta = time.time_since_epoch(); return TargetTimePoint(duration_cast(delta)); -- 2.34.1