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