Futex::futexWait returns FutexResult
[folly.git] / folly / test / FutexTest.cpp
index 71793a97b8edecf942b236dad3e5cdc77285fb7c..7da35b713b680f0b2c8581504e8632cc4e773178 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <glog/logging.h>
 
+#include <folly/Chrono.h>
 #include <folly/portability/GTest.h>
 #include <folly/portability/Time.h>
 
@@ -31,20 +32,21 @@ using namespace folly::detail;
 using namespace folly::test;
 using namespace std;
 using namespace std::chrono;
+using folly::chrono::coarse_steady_clock;
 
 typedef DeterministicSchedule DSched;
 
 template <template <typename> class Atom>
 void run_basic_thread(
     Futex<Atom>& f) {
-  EXPECT_TRUE(f.futexWait(0));
+  EXPECT_EQ(FutexResult::AWOKEN, f.futexWait(0));
 }
 
 template <template <typename> class Atom>
 void run_basic_tests() {
   Futex<Atom> f(0);
 
-  EXPECT_FALSE(f.futexWait(1));
+  EXPECT_EQ(FutexResult::VALUE_CHANGED, f.futexWait(1));
   EXPECT_EQ(f.futexWake(), 0);
 
   auto thr = DSched::thread(std::bind(run_basic_thread<Atom>, std::ref(f)));
@@ -117,6 +119,7 @@ template <template <typename> class Atom>
 void run_wait_until_tests() {
   liveClockWaitUntilTests<Atom, system_clock, system_clock::duration>();
   liveClockWaitUntilTests<Atom, steady_clock, steady_clock::duration>();
+  liveClockWaitUntilTests<Atom, steady_clock, coarse_steady_clock::duration>();
 
   typedef duration<int64_t, std::ratio<1, 10000000>> decimicroseconds;
   liveClockWaitUntilTests<Atom, system_clock, decimicroseconds>();
@@ -126,6 +129,7 @@ template <>
 void run_wait_until_tests<DeterministicAtomic>() {
   deterministicAtomicWaitUntilTests<system_clock>();
   deterministicAtomicWaitUntilTests<steady_clock>();
+  deterministicAtomicWaitUntilTests<coarse_steady_clock>();
 }
 
 uint64_t diff(uint64_t a, uint64_t b) {
@@ -187,7 +191,8 @@ void run_wake_blocked_test() {
   for (auto delay = std::chrono::milliseconds(1);; delay *= 2) {
     bool success = false;
     Futex<Atom> f(0);
-    auto thr = DSched::thread([&] { success = f.futexWait(0); });
+    auto thr = DSched::thread(
+        [&] { success = FutexResult::AWOKEN == f.futexWait(0); });
     /* sleep override */ std::this_thread::sleep_for(delay);
     f.store(1);
     f.futexWake(1);