Commit be0f84c4 authored by Tianshu Bao's avatar Tianshu Bao Committed by Facebook Github Bot

Back out "[folly] Avoid executor re-queue in collect[All]SemiFuture"

Summary: Original commit changeset: e533bfa6b9d2

Reviewed By: heslami

Differential Revision: D14818275

fbshipit-source-id: 06ecb8058538ca150b941df56a050cf572f7eeea
parent 2b7c94c6
...@@ -1548,8 +1548,7 @@ collectAllSemiFuture(Fs&&... fs) { ...@@ -1548,8 +1548,7 @@ collectAllSemiFuture(Fs&&... fs) {
auto ctx = std::make_shared<Context>(); auto ctx = std::make_shared<Context>();
futures::detail::foreach( futures::detail::foreach(
[&](auto i, auto&& f) { [&](auto i, auto&& f) {
auto g = std::move(f).via(&InlineExecutor::instance()); f.setCallback_([i, ctx](auto&& t) {
g.setCallback_([i, ctx](auto&& t) {
std::get<i.value>(ctx->results) = std::move(t); std::get<i.value>(ctx->results) = std::move(t);
}); });
}, },
...@@ -1598,8 +1597,8 @@ collectAllSemiFuture(InputIterator first, InputIterator last) { ...@@ -1598,8 +1597,8 @@ collectAllSemiFuture(InputIterator first, InputIterator last) {
auto ctx = std::make_shared<Context>(size_t(std::distance(first, last))); auto ctx = std::make_shared<Context>(size_t(std::distance(first, last)));
for (size_t i = 0; first != last; ++first, ++i) { for (size_t i = 0; first != last; ++first, ++i) {
auto f = std::move(*first).via(&InlineExecutor::instance()); first->setCallback_(
f.setCallback_([i, ctx](Try<T>&& t) { ctx->results[i] = std::move(t); }); [i, ctx](Try<T>&& t) { ctx->results[i] = std::move(t); });
} }
auto future = ctx->p.getSemiFuture(); auto future = ctx->p.getSemiFuture();
...@@ -1658,8 +1657,7 @@ collectSemiFuture(InputIterator first, InputIterator last) { ...@@ -1658,8 +1657,7 @@ collectSemiFuture(InputIterator first, InputIterator last) {
auto ctx = std::make_shared<Context>(std::distance(first, last)); auto ctx = std::make_shared<Context>(std::distance(first, last));
for (size_t i = 0; first != last; ++first, ++i) { for (size_t i = 0; first != last; ++first, ++i) {
auto f = std::move(*first).via(&InlineExecutor::instance()); first->setCallback_([i, ctx](Try<T>&& t) {
f.setCallback_([i, ctx](Try<T>&& t) {
if (t.hasException()) { if (t.hasException()) {
if (!ctx->threw.exchange(true, std::memory_order_relaxed)) { if (!ctx->threw.exchange(true, std::memory_order_relaxed)) {
ctx->p.setException(std::move(t.exception())); ctx->p.setException(std::move(t.exception()));
...@@ -1714,8 +1712,7 @@ collectSemiFuture(Fs&&... fs) { ...@@ -1714,8 +1712,7 @@ collectSemiFuture(Fs&&... fs) {
auto ctx = std::make_shared<Context>(); auto ctx = std::make_shared<Context>();
futures::detail::foreach( futures::detail::foreach(
[&](auto i, auto&& f) { [&](auto i, auto&& f) {
auto g = std::move(f).via(&InlineExecutor::instance()); f.setCallback_([i, ctx](auto&& t) {
g.setCallback_([i, ctx](auto&& t) {
if (t.hasException()) { if (t.hasException()) {
if (!ctx->threw.exchange(true, std::memory_order_relaxed)) { if (!ctx->threw.exchange(true, std::memory_order_relaxed)) {
ctx->p.setException(std::move(t.exception())); ctx->p.setException(std::move(t.exception()));
......
...@@ -30,13 +30,6 @@ static eggs_t eggs("eggs"); ...@@ -30,13 +30,6 @@ static eggs_t eggs("eggs");
auto rng = std::mt19937(folly::randomNumberSeed()); auto rng = std::mt19937(folly::randomNumberSeed());
class NoAddExecutor : public folly::Executor {
public:
void add(Func) override {
throw eggs;
}
};
TEST(Collect, collectAll) { TEST(Collect, collectAll) {
// returns a vector variant // returns a vector variant
{ {
...@@ -786,43 +779,6 @@ TEST(Collect, collectAllNone) { ...@@ -786,43 +779,6 @@ TEST(Collect, collectAllNone) {
EXPECT_TRUE(f.isReady()); EXPECT_TRUE(f.isReady());
} }
TEST(Collect, collectNoRequeue) {
NoAddExecutor executor;
std::vector<Future<int>> futures;
for (int i = 0; i < 10; ++i) {
futures.emplace_back(makeFuture(i).via(&executor));
}
EXPECT_NO_THROW(collect(futures).get());
}
TEST(Collect, collectVariadicNoRequeue) {
NoAddExecutor executor;
auto f1 = makeFuture(0).via(&executor);
auto f2 = makeFuture(1).via(&executor);
EXPECT_NO_THROW(collect(f1, f2).get());
}
TEST(Collect, collectAllNoRequeue) {
NoAddExecutor executor;
std::vector<Future<int>> futures;
for (int i = 0; i < 10; ++i) {
futures.emplace_back(makeFuture(i).via(&executor));
}
auto results = collectAll(futures).get();
for (auto& t : results) {
EXPECT_FALSE(t.hasException());
}
}
TEST(Collect, collectAllVariadicNoRequeue) {
NoAddExecutor executor;
auto f1 = makeFuture(0).via(&executor);
auto f2 = makeFuture(1).via(&executor);
auto results = collectAll(f1, f2).get();
EXPECT_FALSE(std::get<0>(results).hasException());
EXPECT_FALSE(std::get<1>(results).hasException());
}
TEST(Collect, noDefaultConstructor) { TEST(Collect, noDefaultConstructor) {
struct A { struct A {
explicit A(size_t /* x */) {} explicit A(size_t /* x */) {}
......
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