Use MemoryIdler in SaturatingSemaphore
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 19 Jan 2018 19:47:48 +0000 (11:47 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 19 Jan 2018 19:51:29 +0000 (11:51 -0800)
Summary:
[Folly] Use `MemoryIdler` in `SaturatingSemaphore`.

As is used in `Baton`.

And merge the two invocations of `futexWait` and `futexWaitUntil` - `futexWaitUntil` also tests for the max-deadline internally.

Reviewed By: djwatson

Differential Revision: D6720045

fbshipit-source-id: a48187a6c866dbf99bb5c7283e0288b939bef2e5

folly/synchronization/SaturatingSemaphore.h

index 8d40b85..bc0eba6 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <folly/Likely.h>
 #include <folly/detail/Futex.h>
+#include <folly/detail/MemoryIdler.h>
 #include <folly/portability/Asm.h>
 #include <folly/synchronization/WaitOptions.h>
 
@@ -304,11 +305,7 @@ FOLLY_NOINLINE bool SaturatingSemaphore<MayBlock, Atom>::tryWaitSlow(
             continue;
           }
         }
-        if (deadline == std::chrono::time_point<Clock, Duration>::max()) {
-          state_.futexWait(BLOCKED);
-        } else {
-          state_.futexWaitUntil(BLOCKED, deadline);
-        }
+        detail::MemoryIdler::futexWaitUntil(state_, BLOCKED, deadline);
       }
     }
     asm_volatile_pause();