Futex::futexWait returns FutexResult
[folly.git] / folly / detail / MemoryIdler.h
index 13fe453ef063c07dd47524e82e150f972ae0ed31..caac253e014be4bd99a749f74f51a90a85daa216 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <atomic>
 #include <chrono>
 
-#include <folly/AtomicStruct.h>
-#include <folly/Hash.h>
-#include <folly/Traits.h>
 #include <folly/detail/Futex.h>
+#include <folly/hash/Hash.h>
+#include <folly/synchronization/AtomicStruct.h>
 #include <folly/system/ThreadId.h>
 
-namespace folly {
-
-// gcc 4.7 doesn't do std::is_trivial correctly, override so we can use
-// AtomicStruct<duration>
-template <>
-struct IsTriviallyCopyable<std::chrono::steady_clock::duration>
-  : std::true_type {};
-
-}
-
 namespace folly { namespace detail {
 
 /// MemoryIdler provides helper routines that allow routines to return
@@ -113,7 +102,7 @@ struct MemoryIdler {
   template <
       template <typename> class Atom,
       typename Clock = std::chrono::steady_clock>
-  static bool futexWait(
+  static FutexResult futexWait(
       Futex<Atom>& fut,
       uint32_t expected,
       uint32_t waitMask = -1,
@@ -121,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);
@@ -139,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;
       }
     }
 
@@ -150,4 +138,5 @@ struct MemoryIdler {
   }
 };
 
-}} // namespace folly::detail
+} // namespace detail
+} // namespace folly