Commit 44a17b1f authored by Chris Keeline's avatar Chris Keeline Committed by Facebook Github Bot

Skip shared_ptr in futures waitImpl

Summary:
wait() is guaranteed to succeed and not throw for either Baton type, so
using a reference here is safe. When the future is completed on another thread,
the shared_ptr causes cache contention.

```
Thread 1            Thread 2
make_shared/inc
inc
...
                    dec ref
dec ref/free
```

Reviewed By: yfeldblum

Differential Revision: D17077672

fbshipit-source-id: a6010ed159353decefbd5c51f4347370b16f7f60
parent 8faaa1a9
......@@ -2125,14 +2125,14 @@ void waitImpl(FutureType& f) {
Promise<T> promise;
auto ret = convertFuture(promise.getSemiFuture(), f);
auto baton = std::make_shared<FutureBatonType>();
f.setCallback_([baton, promise = std::move(promise)](
FutureBatonType baton;
f.setCallback_([&baton, promise = std::move(promise)](
Executor::KeepAlive<>&&, Try<T>&& t) mutable {
promise.setTry(std::move(t));
baton->post();
baton.post();
});
f = std::move(ret);
baton->wait();
baton.wait();
assert(f.isReady());
}
......
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