/*
+ * Copyright 2016 Facebook, Inc.
+ *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* specific language governing permissions and limitations
* under the License.
*/
-#include "folly/io/async/EventHandler.h"
-#include "folly/io/async/EventBase.h"
+#include <folly/io/async/EventHandler.h>
+#include <folly/io/async/EventBase.h>
#include <assert.h>
if (isHandlerRegistered()) {
// If the new events are the same are the same as the already registered
// flags, we don't have to do anything. Just return.
+ auto flags = event_ref_flags(&event_);
if (events == event_.ev_events &&
- static_cast<bool>(event_.ev_flags & EVLIST_INTERNAL) == internal) {
+ static_cast<bool>(flags & EVLIST_INTERNAL) == internal) {
return true;
}
// Set EVLIST_INTERNAL if this is an internal event
if (internal) {
- event_.ev_flags |= EVLIST_INTERNAL;
+ event_ref_flags(&event_) |= EVLIST_INTERNAL;
}
// Add the event.
void EventHandler::libeventCallback(int fd, short events, void* arg) {
EventHandler* handler = reinterpret_cast<EventHandler*>(arg);
assert(fd == handler->event_.ev_fd);
+ (void)fd; // prevent unused variable warnings
+
+ auto observer = handler->eventBase_->getExecutionObserver();
+ if (observer) {
+ observer->starting(reinterpret_cast<uintptr_t>(handler));
+ }
// this can't possibly fire if handler->eventBase_ is nullptr
- (void) handler->eventBase_->bumpHandlingTime();
+ handler->eventBase_->bumpHandlingTime();
handler->handlerReady(events);
+
+ if (observer) {
+ observer->stopped(reinterpret_cast<uintptr_t>(handler));
+ }
}
void EventHandler::setEventBase(EventBase* eventBase) {
}
bool EventHandler::isPending() const {
- if (event_.ev_flags & EVLIST_ACTIVE) {
+ if (event_ref_flags(&event_) & EVLIST_ACTIVE) {
if (event_.ev_res & EV_READ) {
return true;
}