Commit c79a6fde authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Allow the WTCallback to be used with timer managers that have timeoutExpired methods

Summary: Allow the WTCallback to be used with timer managers that have timeoutExpired methods

Reviewed By: kevin-vigor

Differential Revision: D20503031

fbshipit-source-id: df91f1e2531f5c54943d3540bdf7c3d357c9fda1
parent 101ac180
......@@ -46,7 +46,7 @@ ThreadWheelTimekeeperHighRes::~ThreadWheelTimekeeperHighRes() {
}
SemiFuture<Unit> ThreadWheelTimekeeperHighRes::after(HighResDuration dur) {
auto cob = WTCallback<HighResDuration>::create(&eventBase_);
auto cob = WTCallback<HHWheelTimerHighRes>::create(&eventBase_);
auto f = cob->getSemiFuture();
//
// Even shared_ptr of cob is captured in lambda this is still somewhat *racy*
......
......@@ -48,7 +48,7 @@ ThreadWheelTimekeeper::~ThreadWheelTimekeeper() {
}
SemiFuture<Unit> ThreadWheelTimekeeper::after(HighResDuration dur) {
auto cob = WTCallback<Duration>::create(&eventBase_);
auto cob = WTCallback<HHWheelTimer>::create(&eventBase_);
auto f = cob->getSemiFuture();
//
// Even shared_ptr of cob is captured in lambda this is still somewhat *racy*
......
......@@ -21,9 +21,9 @@
namespace folly {
// Our Callback object for HHWheelTimer
template <class TDuration>
struct WTCallback : public std::enable_shared_from_this<WTCallback<TDuration>>,
public folly::HHWheelTimerBase<TDuration>::Callback {
template <class TBase>
struct WTCallback : public std::enable_shared_from_this<WTCallback<TBase>>,
public TBase::Callback {
struct PrivateConstructorTag {};
public:
......@@ -84,17 +84,16 @@ struct WTCallback : public std::enable_shared_from_this<WTCallback<TDuration>>,
// This is not racing with timeoutExpired anymore because this is called
// through Future, which means Core is still alive and keeping a ref count
// on us, so what timeouExpired is doing won't make the object go away
(*rBase)->runInEventBaseThread(
[me = std::enable_shared_from_this<
WTCallback<TDuration>>::shared_from_this(),
ew = std::move(ew)]() mutable {
me->cancelTimeout();
// Don't need Promise anymore, break the circular reference
auto promise = me->stealPromise();
if (!promise.isFulfilled()) {
promise.setException(std::move(ew));
}
});
(*rBase)->runInEventBaseThread([me = std::enable_shared_from_this<
WTCallback<TBase>>::shared_from_this(),
ew = std::move(ew)]() mutable {
me->cancelTimeout();
// Don't need Promise anymore, break the circular reference
auto promise = me->stealPromise();
if (!promise.isFulfilled()) {
promise.setException(std::move(ew));
}
});
}
};
......
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