Commit 138b7236 authored by Francis Ma's avatar Francis Ma Committed by facebook-github-bot-4

Decouple future and fiber for mobile

Summary:
folly::fibers have a bunch of dependencies that are shaky on mobiles.
Decoupling it by using folly::Baton instead of folly::fibers::Baton. Should have
zero effect on fbcode cases.

Reviewed By: djwatson, yfeldblum

Differential Revision: D2821603

fb-gh-sync-id: 0ce3472c9eedf97224e8584d25e04515396cd18e
parent 76dabfa2
......@@ -217,6 +217,13 @@ struct Baton {
}
}
/// Similar to timed_wait, but with a duration.
template <typename Clock = std::chrono::steady_clock, typename Duration>
bool timed_wait(const Duration& duration) {
auto deadline = Clock::now() + duration;
return timed_wait(deadline);
}
/// Similar to wait, but doesn't block the thread if it hasn't been posted.
///
/// try_wait has the following semantics:
......
......@@ -21,17 +21,32 @@
#include <chrono>
#include <random>
#include <thread>
#include <folly/experimental/fibers/Baton.h>
#include <folly/Baton.h>
#include <folly/Optional.h>
#include <folly/Random.h>
#include <folly/Traits.h>
#include <folly/futures/detail/Core.h>
#include <folly/futures/Timekeeper.h>
#if defined(__ANDROID__) || defined(__APPLE__)
#define FOLLY_FUTURE_USING_FIBER 0
#else
#define FOLLY_FUTURE_USING_FIBER 1
#include <folly/experimental/fibers/Baton.h>
#endif
namespace folly {
class Timekeeper;
namespace detail {
#if FOLLY_FUTURE_USING_FIBER
typedef folly::fibers::Baton FutureBatonType;
#else
typedef folly::Baton<> FutureBatonType;
#endif
}
namespace detail {
std::shared_ptr<Timekeeper> getTimekeeperSingleton();
}
......@@ -937,7 +952,7 @@ void waitImpl(Future<T>& f) {
// short-circuit if there's nothing to do
if (f.isReady()) return;
folly::fibers::Baton baton;
FutureBatonType baton;
f.setCallback_([&](const Try<T>& t) { baton.post(); });
baton.wait();
assert(f.isReady());
......@@ -950,7 +965,7 @@ void waitImpl(Future<T>& f, Duration dur) {
folly::MoveWrapper<Promise<T>> promise;
auto ret = promise->getFuture();
auto baton = std::make_shared<folly::fibers::Baton>();
auto baton = std::make_shared<FutureBatonType>();
f.setCallback_([baton, promise](Try<T>&& t) mutable {
promise->setTry(std::move(t));
baton->post();
......
......@@ -16,6 +16,7 @@
#include <memory>
#include <mutex>
#include <queue>
#include <gtest/gtest.h>
#include <glog/logging.h>
......
......@@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <queue>
#include <gtest/gtest.h>
#include <folly/futures/Future.h>
......
......@@ -16,6 +16,7 @@
#include <memory>
#include <mutex>
#include <queue>
#include <gtest/gtest.h>
#include <glog/logging.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment