}
EventBase::~EventBase() {
+ // Call all destruction callbacks, before we start cleaning up our state.
+ while (!onDestructionCallbacks_.empty()) {
+ LoopCallback* callback = &onDestructionCallbacks_.front();
+ onDestructionCallbacks_.pop_front();
+ callback->runLoopCallback();
+ }
+
// Delete any unfired CobTimeout objects, so that we don't leak memory
// (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
}
}
+void EventBase::runOnDestruction(LoopCallback* callback) {
+ DCHECK(isInEventBaseThread());
+ callback->cancelLoopCallback();
+ onDestructionCallbacks_.push_back(*callback);
+}
+
bool EventBase::runInEventBaseThread(void (*fn)(void*), void* arg) {
// Send the message.
// It will be received by the FunctionRunner in the EventBase's thread.