Commit df5cac55 authored by Veselin Petrov's avatar Veselin Petrov Committed by Facebook GitHub Bot

Enable basic folly::Future support for XROS builds.

Summary:
`folly/io/async:async_base` is not fully migrated to XROS, mitigate futures implementation for now:
* Craft out `fibers::Baton` and `IO pool` dependencies from futures.
* Add futures to CI targets.
* Add build time test to ensure `folly::Future<Unit>` symbols are generated.

This closely follows mitigation in `AROS` branch:
https://www.internalfb.com/code/aros/[a0c19baba13b]/xros/third-party/folly/folly/futures/Future.h

(any suggestions on how to properly proceed with such change are greatly appreciated!)

Reviewed By: egorich239

Differential Revision: D31497625

fbshipit-source-id: c0b2406496ca3c4f69ddadd61dbd1d75f309e8a1
parent 27ff58f4
......@@ -34,13 +34,21 @@
#include <folly/futures/detail/Core.h>
#include <folly/lang/Pretty.h>
#if defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
#include <folly/synchronization/Baton.h>
#endif
namespace folly {
class Timekeeper;
namespace futures {
namespace detail {
#if defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
typedef folly::Baton<> FutureBatonType;
#else
typedef folly::fibers::Baton FutureBatonType;
#endif
} // namespace detail
} // namespace futures
......@@ -461,13 +469,18 @@ class WaitExecutor final : public folly::Executor {
void drive() {
baton_.wait();
#if !defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
fibers::runInMainContext([&]() {
#endif
baton_.reset();
auto funcs = std::move(queue_.wlock()->funcs);
for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
#if !defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
});
#endif
}
using Clock = std::chrono::steady_clock;
......@@ -476,14 +489,18 @@ class WaitExecutor final : public folly::Executor {
if (!baton_.try_wait_until(deadline)) {
return false;
}
#if !defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
return fibers::runInMainContext([&]() {
#endif
baton_.reset();
auto funcs = std::move(queue_.wlock()->funcs);
for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
return true;
#if !defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
});
#endif
}
void detach() {
......
......@@ -33,7 +33,9 @@
#include <folly/executors/DrivableExecutor.h>
#include <folly/executors/TimedDrivableExecutor.h>
#include <folly/experimental/coro/Traits.h>
#if !defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
#include <folly/fibers/Baton.h>
#endif
#include <folly/functional/Invoke.h>
#include <folly/futures/Portability.h>
#include <folly/futures/Promise.h>
......@@ -2144,8 +2146,10 @@ template <class F>
auto when(bool p, F&& thunk)
-> decltype(std::declval<invoke_result_t<F>>().unit());
#if !defined(FOLLY_DISABLE_FUTURE_FIBERS_BATON)
SemiFuture<Unit> wait(std::unique_ptr<fibers::Baton> baton);
SemiFuture<Unit> wait(std::shared_ptr<fibers::Baton> baton);
#endif
/**
* Returns a lazy SemiFuture constructed by f, which also ensures that ensure is
......
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