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