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