}
// The CobTimeout object was allocated on the heap by runAfterDelay(),
- // so delete it now that the it has fired.
+ // so delete it now that it has fired.
+ delete this;
+}
+
+void EventBase::CobTimeout::callbackCanceled() noexcept {
+ // The CobTimeout object was allocated on the heap by runAfterDelay(),
+ // so delete it now that it has been canceled.
delete this;
}
}
VLOG(5) << "EventBase(): Created.";
initNotificationQueue();
+ wheelTimer_ = HHWheelTimer::UniquePtr(new HHWheelTimer(this));
RequestContext::saveContext();
}
throw std::invalid_argument("EventBase(): event base cannot be nullptr");
}
initNotificationQueue();
+ wheelTimer_ = HHWheelTimer::UniquePtr(new HHWheelTimer(this));
RequestContext::saveContext();
}
// (Note that we don't fire them. The caller is responsible for cleaning up
// its own data structures if it destroys the EventBase with unfired events
// remaining.)
- while (!pendingCobTimeouts_.empty()) {
- CobTimeout* timeout = &pendingCobTimeouts_.front();
- delete timeout;
- }
+ wheelTimer_->cancelAll();
while (!runBeforeLoopCallbacks_.empty()) {
delete &runBeforeLoopCallbacks_.front();
bool EventBase::tryRunAfterDelay(const Cob& cob,
int milliseconds,
TimeoutManager::InternalEnum in) {
- CobTimeout* timeout = new CobTimeout(this, cob, in);
- if (!timeout->scheduleTimeout(milliseconds)) {
- delete timeout;
- return false;
- }
- pendingCobTimeouts_.push_back(*timeout);
+ // A previous implementation could fail, and the API is retained for
+ // backwards compatibility.
+ wheelTimer_->scheduleTimeout(
+ new CobTimeout(cob),
+ std::chrono::milliseconds(milliseconds));
return true;
}
#include <glog/logging.h>
#include <folly/io/async/AsyncTimeout.h>
+#include <folly/io/async/HHWheelTimer.h>
#include <folly/io/async/TimeoutManager.h>
#include <folly/io/async/Request.h>
#include <folly/Executor.h>
// small object used as a callback arg with enough info to execute the
// appropriate client-provided Cob
- class CobTimeout : public AsyncTimeout {
+ class CobTimeout : public HHWheelTimer::Callback {
public:
- CobTimeout(EventBase* b, const Cob& c, TimeoutManager::InternalEnum in)
- : AsyncTimeout(b, in), cob_(c) {}
+ explicit CobTimeout(const Cob& c) : cob_(c) {}
- virtual void timeoutExpired() noexcept;
+ void timeoutExpired() noexcept override;
+
+ void callbackCanceled() noexcept override;
private:
Cob cob_;
-
- public:
- typedef boost::intrusive::list_member_hook<
- boost::intrusive::link_mode<boost::intrusive::auto_unlink> > ListHook;
-
- ListHook hook;
-
- typedef boost::intrusive::list<
- CobTimeout,
- boost::intrusive::member_hook<CobTimeout, ListHook, &CobTimeout::hook>,
- boost::intrusive::constant_time_size<false> > List;
};
typedef LoopCallback::List LoopCallbackList;
void initNotificationQueue();
- CobTimeout::List pendingCobTimeouts_;
+ HHWheelTimer::UniquePtr wheelTimer_;
LoopCallbackList loopCallbacks_;
LoopCallbackList runBeforeLoopCallbacks_;