Commit f8ae7092 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix up fiber-related guards in futures code

Summary:
[Folly] Fix up fiber-related guards in futures code. Because of cyclic `#include`s the preprocessor symbol definition must be moved.

Fixes #1061.

Reviewed By: wez, andriigrynenko

Differential Revision: D14555070

fbshipit-source-id: 5e4966fc0f98351924c00a459cc2d8893df4b368
parent 08f846dc
......@@ -118,6 +118,8 @@ coro::Task<void> Semaphore::co_wait() {
#endif
#if FOLLY_FUTURE_USING_FIBER
SemiFuture<Unit> Semaphore::future_wait() {
auto oldVal = tokens_.load(std::memory_order_acquire);
do {
......@@ -138,6 +140,8 @@ SemiFuture<Unit> Semaphore::future_wait() {
return makeSemiFuture();
}
#endif
size_t Semaphore::getCapacity() const {
return capacity_;
}
......
......@@ -58,11 +58,15 @@ class Semaphore {
#endif
#if FOLLY_FUTURE_USING_FIBER
/*
* Wait for capacity in the semaphore.
*/
SemiFuture<Unit> future_wait();
#endif
size_t getCapacity() const;
private:
......
......@@ -1597,7 +1597,11 @@ TEST(FiberManager, semaphore) {
if (j % 2) {
sem.wait();
} else {
#if FOLLY_FUTURE_USING_FIBER
sem.future_wait().get();
#else
sem.wait();
#endif
}
++counter;
sem.signal();
......
......@@ -28,14 +28,9 @@
#include <folly/futures/detail/Core.h>
#include <folly/synchronization/Baton.h>
#ifndef FOLLY_FUTURE_USING_FIBER
#if FOLLY_MOBILE || defined(__APPLE__)
#define FOLLY_FUTURE_USING_FIBER 0
#else
#define FOLLY_FUTURE_USING_FIBER 1
#if FOLLY_FUTURE_USING_FIBER
#include <folly/fibers/Baton.h>
#endif
#endif
namespace folly {
......
......@@ -58,6 +58,7 @@ Future<Unit> sleepUnsafe(Duration dur, Timekeeper* tk) {
}
#if FOLLY_FUTURE_USING_FIBER
namespace {
class FutureWaiter : public fibers::Baton::Waiter {
public:
......@@ -83,6 +84,7 @@ SemiFuture<Unit> wait(std::unique_ptr<fibers::Baton> baton) {
new FutureWaiter(std::move(promise), std::move(baton));
return sf;
}
#endif
} // namespace futures
......
......@@ -31,6 +31,7 @@
#include <folly/executors/DrivableExecutor.h>
#include <folly/executors/TimedDrivableExecutor.h>
#include <folly/functional/Invoke.h>
#include <folly/futures/Portability.h>
#include <folly/futures/Promise.h>
#include <folly/futures/detail/Types.h>
#include <folly/lang/Exception.h>
......
/*
* Copyright 2019-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <folly/Portability.h>
#if FOLLY_MOBILE || defined(__APPLE__)
#define FOLLY_FUTURE_USING_FIBER 0
#else
#define FOLLY_FUTURE_USING_FIBER 1
#endif
......@@ -23,6 +23,7 @@
#include <folly/Try.h>
#include <folly/functional/Invoke.h>
#include <folly/futures/Future.h>
#include <folly/futures/Portability.h>
#include <folly/futures/Promise.h>
namespace folly {
......@@ -145,8 +146,12 @@ auto mapTry(Executor& exec, Collection&& c, F&& func)
return mapTry(exec, c.begin(), c.end(), std::forward<F>(func));
}
#if FOLLY_FUTURE_USING_FIBER
SemiFuture<Unit> wait(std::unique_ptr<fibers::Baton> baton);
#endif
} // namespace futures
/**
......
......@@ -1627,6 +1627,7 @@ TEST(Future, ThenRecursion) {
}
#if FOLLY_FUTURE_USING_FIBER
TEST(Future, BatonWait) {
auto baton = std::make_unique<fibers::Baton>();
bool posted{false};
......@@ -1644,4 +1645,5 @@ TEST(Future, BatonWait) {
.getVia(&executor);
EXPECT_TRUE(postFuture.isReady());
}
#endif
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