From e229101b0e2fc1d9ccfbcb10be991cb62e19d32d Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Tue, 9 Jan 2018 22:39:13 -0800 Subject: [PATCH] Futex::futexWait returns FutexResult Summary: [Folly] `Futex::futexWait` returns `FutexResult`. Reviewed By: nbronson Differential Revision: D6673871 fbshipit-source-id: 378c69d8362970e985da31e31d8e9b0179d2917f --- folly/detail/Futex.h | 4 ++-- folly/detail/MemoryIdler.h | 5 ++-- folly/test/FutexTest.cpp | 7 +++--- folly/test/MemoryIdlerTest.cpp | 43 ++++++++++++++++++++-------------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/folly/detail/Futex.h b/folly/detail/Futex.h index 1e72b15c..000bf1a6 100644 --- a/folly/detail/Futex.h +++ b/folly/detail/Futex.h @@ -52,10 +52,10 @@ struct Futex : Atom, boost::noncopyable { /** Puts the thread to sleep if this->load() == expected. Returns true when * it is returning because it has consumed a wake() event, false for any * other return (signal, this->load() != expected, or spurious wakeup). */ - bool futexWait(uint32_t expected, uint32_t waitMask = -1) { + FutexResult futexWait(uint32_t expected, uint32_t waitMask = -1) { auto rv = futexWaitImpl(expected, nullptr, nullptr, waitMask); assert(rv != FutexResult::TIMEDOUT); - return rv == FutexResult::AWOKEN; + return rv; } /** Similar to futexWait but also accepts a deadline until when the wait call diff --git a/folly/detail/MemoryIdler.h b/folly/detail/MemoryIdler.h index 3c987cc9..caac253e 100644 --- a/folly/detail/MemoryIdler.h +++ b/folly/detail/MemoryIdler.h @@ -102,7 +102,7 @@ struct MemoryIdler { template < template class Atom, typename Clock = std::chrono::steady_clock> - static bool futexWait( + static FutexResult futexWait( Futex& fut, uint32_t expected, uint32_t waitMask = -1, @@ -110,7 +110,6 @@ struct MemoryIdler { defaultIdleTimeout.load(std::memory_order_acquire), size_t stackToRetain = kDefaultStackToRetain, float timeoutVariationFrac = 0.5) { - if (idleTimeout == Clock::duration::max()) { // no need to use futexWaitUntil if no timeout is possible return fut.futexWait(expected, waitMask); @@ -128,7 +127,7 @@ struct MemoryIdler { // finished before timeout hit, no flush assert(rv == FutexResult::VALUE_CHANGED || rv == FutexResult::AWOKEN || rv == FutexResult::INTERRUPTED); - return rv == FutexResult::AWOKEN; + return rv; } } diff --git a/folly/test/FutexTest.cpp b/folly/test/FutexTest.cpp index 464c8524..7da35b71 100644 --- a/folly/test/FutexTest.cpp +++ b/folly/test/FutexTest.cpp @@ -39,14 +39,14 @@ typedef DeterministicSchedule DSched; template