Commit ac75bb2d authored by James Sedgwick's avatar James Sedgwick Committed by facebook-github-bot-1

revert D2379210

Summary: This broke EventBase tests, which I managed not to run because they're marked as extended for some reason :( I don't have time to take another stab at this at the moment so I'm reverting for now

Reviewed By: @djwatson

Differential Revision: D2467789
parent 09312dae
...@@ -123,13 +123,7 @@ void EventBase::CobTimeout::timeoutExpired() noexcept { ...@@ -123,13 +123,7 @@ void EventBase::CobTimeout::timeoutExpired() noexcept {
} }
// The CobTimeout object was allocated on the heap by runAfterDelay(), // The CobTimeout object was allocated on the heap by runAfterDelay(),
// so delete it now that it has fired. // so delete it now that the 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; delete this;
} }
...@@ -181,7 +175,6 @@ EventBase::EventBase(bool enableTimeMeasurement) ...@@ -181,7 +175,6 @@ EventBase::EventBase(bool enableTimeMeasurement)
} }
VLOG(5) << "EventBase(): Created."; VLOG(5) << "EventBase(): Created.";
initNotificationQueue(); initNotificationQueue();
wheelTimer_ = HHWheelTimer::UniquePtr(new HHWheelTimer(this));
RequestContext::saveContext(); RequestContext::saveContext();
} }
...@@ -208,7 +201,6 @@ EventBase::EventBase(event_base* evb, bool enableTimeMeasurement) ...@@ -208,7 +201,6 @@ EventBase::EventBase(event_base* evb, bool enableTimeMeasurement)
throw std::invalid_argument("EventBase(): event base cannot be nullptr"); throw std::invalid_argument("EventBase(): event base cannot be nullptr");
} }
initNotificationQueue(); initNotificationQueue();
wheelTimer_ = HHWheelTimer::UniquePtr(new HHWheelTimer(this));
RequestContext::saveContext(); RequestContext::saveContext();
} }
...@@ -224,7 +216,10 @@ EventBase::~EventBase() { ...@@ -224,7 +216,10 @@ EventBase::~EventBase() {
// (Note that we don't fire them. The caller is responsible for cleaning up // (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 // its own data structures if it destroys the EventBase with unfired events
// remaining.) // remaining.)
wheelTimer_->cancelAll(); while (!pendingCobTimeouts_.empty()) {
CobTimeout* timeout = &pendingCobTimeouts_.front();
delete timeout;
}
while (!runBeforeLoopCallbacks_.empty()) { while (!runBeforeLoopCallbacks_.empty()) {
delete &runBeforeLoopCallbacks_.front(); delete &runBeforeLoopCallbacks_.front();
...@@ -659,11 +654,12 @@ void EventBase::runAfterDelay(const Cob& cob, ...@@ -659,11 +654,12 @@ void EventBase::runAfterDelay(const Cob& cob,
bool EventBase::tryRunAfterDelay(const Cob& cob, bool EventBase::tryRunAfterDelay(const Cob& cob,
int milliseconds, int milliseconds,
TimeoutManager::InternalEnum in) { TimeoutManager::InternalEnum in) {
// A previous implementation could fail, and the API is retained for CobTimeout* timeout = new CobTimeout(this, cob, in);
// backwards compatibility. if (!timeout->scheduleTimeout(milliseconds)) {
wheelTimer_->scheduleTimeout( delete timeout;
new CobTimeout(cob), return false;
std::chrono::milliseconds(milliseconds)); }
pendingCobTimeouts_.push_back(*timeout);
return true; return true;
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <folly/io/async/AsyncTimeout.h> #include <folly/io/async/AsyncTimeout.h>
#include <folly/io/async/HHWheelTimer.h>
#include <folly/io/async/TimeoutManager.h> #include <folly/io/async/TimeoutManager.h>
#include <folly/io/async/Request.h> #include <folly/io/async/Request.h>
#include <folly/Executor.h> #include <folly/Executor.h>
...@@ -650,16 +649,26 @@ class EventBase : private boost::noncopyable, ...@@ -650,16 +649,26 @@ class EventBase : private boost::noncopyable,
// small object used as a callback arg with enough info to execute the // small object used as a callback arg with enough info to execute the
// appropriate client-provided Cob // appropriate client-provided Cob
class CobTimeout : public HHWheelTimer::Callback { class CobTimeout : public AsyncTimeout {
public: public:
explicit CobTimeout(const Cob& c) : cob_(c) {} CobTimeout(EventBase* b, const Cob& c, TimeoutManager::InternalEnum in)
: AsyncTimeout(b, in), cob_(c) {}
void timeoutExpired() noexcept override; virtual void timeoutExpired() noexcept;
void callbackCanceled() noexcept override;
private: private:
Cob cob_; 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; typedef LoopCallback::List LoopCallbackList;
...@@ -672,7 +681,7 @@ class EventBase : private boost::noncopyable, ...@@ -672,7 +681,7 @@ class EventBase : private boost::noncopyable,
void initNotificationQueue(); void initNotificationQueue();
HHWheelTimer::UniquePtr wheelTimer_; CobTimeout::List pendingCobTimeouts_;
LoopCallbackList loopCallbacks_; LoopCallbackList loopCallbacks_;
LoopCallbackList runBeforeLoopCallbacks_; LoopCallbackList runBeforeLoopCallbacks_;
......
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