From: Dave Watson Date: Wed, 22 Apr 2015 16:02:38 +0000 (-0700) Subject: future / fiber integration X-Git-Tag: v0.36.0~14 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=75aef07cbbc9112459c8b2a5b6ee4fdf6b2229ab;p=folly.git future / fiber integration Summary: make future::wait() use fiber's baton, so wait works in threads or in fibers. Much cleaner than making a new FiberRequest type in thrift Test Plan: tests Reviewed By: andrii@fb.com Subscribers: doug, alandau, bmatheny, mshneer, andrii, folly-diffs@, yitingli, yfeldblum, jsedgwick, chalfant FB internal diff: D1996283 Signature: t1:1996283:1429144165:da5dc6b1f2a053a45efd39877e79169e3fba810c --- diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index f141b268..a4ec35f0 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -896,7 +896,7 @@ void waitImpl(Future& f) { // short-circuit if there's nothing to do if (f.isReady()) return; - Baton<> baton; + folly::fibers::Baton baton; f = f.then([&](Try t) { baton.post(); return makeFuture(std::move(t)); @@ -916,7 +916,7 @@ void waitImpl(Future& f, Duration dur) { // short-circuit if there's nothing to do if (f.isReady()) return; - auto baton = std::make_shared>(); + auto baton = std::make_shared(); f = f.then([baton](Try t) { baton->post(); return makeFuture(std::move(t)); @@ -925,7 +925,7 @@ void waitImpl(Future& f, Duration dur) { // Let's preserve the invariant that if we did not timeout (timed_wait returns // true), then the returned Future is complete when it is returned to the // caller. We need to wait out the race for that Future to complete. - if (baton->timed_wait(std::chrono::system_clock::now() + dur)) { + if (baton->timed_wait(dur)) { while (!f.isReady()) { std::this_thread::yield(); } diff --git a/folly/futures/test/FutureTest.cpp b/folly/futures/test/FutureTest.cpp index f2529253..00a56be6 100644 --- a/folly/futures/test/FutureTest.cpp +++ b/folly/futures/test/FutureTest.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include