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

Use stealPromise v.s. releasePromise in ThreadedWheelTimekeeper

Summary:
[Folly] Use `stealPromise` v.s. `releasePromise` in `ThreadedWheelTimekeeper`.

This makes it easier to to combine working with the promise with releasing the promise.

Differential Revision: D6842090

fbshipit-source-id: ff3859ed25c1d2a779068603109d1fc801771377
parent a4290316
......@@ -48,11 +48,11 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>,
return promise_.getFuture();
}
void releasePromise() {
Promise<Unit> stealPromise() {
// Don't need promise anymore. Break the circular reference as promise_
// is holding a ref count to us via Core. Core won't go away until both
// Promise and Future go away.
promise_ = Promise<Unit>::makeEmpty();
return std::move(promise_);
}
protected:
......@@ -60,9 +60,8 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>,
Promise<Unit> promise_;
void timeoutExpired() noexcept override {
promise_.setValue();
// Don't need Promise anymore, break the circular reference
releasePromise();
stealPromise().setValue();
}
void interruptHandler() {
......@@ -74,7 +73,7 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback>,
base_->runInEventBaseThread([me = shared_from_this()] {
me->cancelTimeout();
// Don't need Promise anymore, break the circular reference
me->releasePromise();
(void)me->stealPromise();
});
}
};
......@@ -127,7 +126,7 @@ Future<Unit> ThreadWheelTimekeeper::after(Duration dur) {
// This is either called from EventBase thread, or here.
// They are somewhat racy but given the rare chance this could fail,
// I don't see it is introducing any problem yet.
cob->releasePromise();
(void)cob->stealPromise();
}
return f;
}
......
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