Commit 1766f03f authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix releaseDeferredExecutor to not access Executor if callback was set

Summary: Instead of using setCallbackAndDetach (which is hard to apply in all cases because of cancellation), this diff fixes releaseDefferedExecutor.

Reviewed By: yfeldblum

Differential Revision: D16189338

fbshipit-source-id: 47ef192dd0cec3c13824071c8ba7e1dd06968a70
parent f8533d7f
......@@ -324,13 +324,6 @@ void FutureBase<T>::setCallback_(
std::forward<F>(func), RequestContext::saveContext(), allowInline);
}
template <class T>
template <class F>
void FutureBase<T>::setCallbackAndDetach_(F&& func) {
setCallback_(std::forward<F>(func));
detach();
}
template <class T>
FutureBase<T>::FutureBase(futures::detail::EmptyConstruct) noexcept
: core_(nullptr) {}
......@@ -874,7 +867,7 @@ SemiFuture<T>::stealDeferredExecutor() const {
template <class T>
void SemiFuture<T>::releaseDeferredExecutor(Core* core) {
if (!core) {
if (!core || core->hasCallback()) {
return;
}
if (auto executor = core->getExecutor()) {
......@@ -2252,7 +2245,7 @@ void waitImpl(FutureType& f) {
Promise<T> promise;
auto ret = convertFuture(promise.getSemiFuture(), f);
auto baton = std::make_shared<FutureBatonType>();
f.setCallbackAndDetach_([baton, promise = std::move(promise)](
f.setCallback_([baton, promise = std::move(promise)](
Executor::KeepAlive<>&&, Try<T>&& t) mutable {
promise.setTry(std::move(t));
baton->post();
......@@ -2287,7 +2280,7 @@ void waitImpl(FutureType& f, Duration dur) {
Promise<T> promise;
auto ret = convertFuture(promise.getSemiFuture(), f);
auto baton = std::make_shared<FutureBatonType>();
f.setCallbackAndDetach_([baton, promise = std::move(promise)](
f.setCallback_([baton, promise = std::move(promise)](
Executor::KeepAlive<>&&, Try<T>&& t) mutable {
promise.setTry(std::move(t));
baton->post();
......
......@@ -261,9 +261,6 @@ class FutureBase {
template <class F>
void setCallback_(F&& func, InlineContinuation = InlineContinuation::forbid);
template <class F>
void setCallbackAndDetach_(F&& func);
/// Provides a threadsafe back-channel so the consumer's thread can send an
/// interrupt-object to the producer's thread.
///
......@@ -553,7 +550,6 @@ class SemiFuture : private futures::detail::FutureBase<T> {
using Base::raise;
using Base::result;
using Base::setCallback_;
using Base::setCallbackAndDetach_;
using Base::valid;
using Base::value;
......@@ -1018,7 +1014,6 @@ class Future : private futures::detail::FutureBase<T> {
using Base::raise;
using Base::result;
using Base::setCallback_;
using Base::setCallbackAndDetach_;
using Base::valid;
using Base::value;
......
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