const struct timeval *tv, int tv_is_absolute);
static inline int event_del_internal(struct event *ev);
- static void event_queue_insert(struct event_base *, struct event *, int);
- static void event_queue_remove(struct event_base *, struct event *, int);
- static void event_queue_reinsert(struct event_base *,struct event *ev,int);
+ static void event_queue_insert_active(struct event_base *, struct event *);
+ static void event_queue_insert_timeout(struct event_base *, struct event *);
+ static void event_queue_insert_inserted(struct event_base *, struct event *);
+ static void event_queue_remove_active(struct event_base *, struct event *);
+ static void event_queue_remove_timeout(struct event_base *, struct event *);
+ static void event_queue_remove_inserted(struct event_base *, struct event *);
++static void event_queue_reinsert_timeout(struct event_base *,struct event *);
+
static int event_haveevents(struct event_base *);
static int event_process_active(struct event_base *);
"event_add: timeout in %d seconds, call %p",
(int)tv->tv_sec, ev->ev_callback));
- event_queue_reinsert(base, ev, EVLIST_TIMEOUT);
- event_queue_insert_timeout(base, ev);
++ event_queue_reinsert_timeout(base, ev);
+
if (common_timeout) {
struct common_timeout_list *ctl =
get_common_timeout_list(base, &ev->ev_timeout);
}
}
- /* Remove 'ev' from 'queue' (EVLIST_...) in base. */
+ #if (EVLIST_INTERNAL >> 4) != 1
+ #error "Mismatch for value of EVLIST_INTERNAL"
+ #endif
+ /* These are a fancy way to spell
+ if (~ev->ev_flags & EVLIST_INTERNAL)
+ base->event_count--/++;
+ */
+ #define DECR_EVENT_COUNT(base,ev) \
+ ((base)->event_count -= (~((ev)->ev_flags >> 4) & 1))
+ #define INCR_EVENT_COUNT(base, ev) \
+ ((base)->event_count += (~((ev)->ev_flags >> 4) & 1))
+
static void
- event_queue_remove(struct event_base *base, struct event *ev, int queue)
+ event_queue_remove_inserted(struct event_base *base, struct event *ev)
{
EVENT_BASE_ASSERT_LOCKED(base);
-
- if (!(ev->ev_flags & queue)) {
+ if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_INSERTED))) {
event_errx(1, "%s: %p(fd %d) not on queue %x", __func__,
- ev, ev->ev_fd, queue);
+ ev, ev->ev_fd, EVLIST_INSERTED);
return;
}
-
- if (~ev->ev_flags & EVLIST_INTERNAL)
- base->event_count--;
-
- ev->ev_flags &= ~queue;
- switch (queue) {
- case EVLIST_INSERTED:
- TAILQ_REMOVE(&base->eventqueue, ev, ev_next);
- break;
- case EVLIST_ACTIVE:
- base->event_count_active--;
- TAILQ_REMOVE(&base->activequeues[ev->ev_pri],
- ev, ev_active_next);
- break;
- case EVLIST_TIMEOUT:
- if (is_common_timeout(&ev->ev_timeout, base)) {
- struct common_timeout_list *ctl =
- get_common_timeout_list(base, &ev->ev_timeout);
- TAILQ_REMOVE(&ctl->events, ev,
- ev_timeout_pos.ev_next_with_common_timeout);
- } else {
- min_heap_erase(&base->timeheap, ev);
- }
- break;
- default:
- event_errx(1, "%s: unknown queue %x", __func__, queue);
+ DECR_EVENT_COUNT(base, ev);
+ ev->ev_flags &= ~EVLIST_INSERTED;
+ TAILQ_REMOVE(&base->eventqueue, ev, ev_next);
+ }
+ static void
+ event_queue_remove_active(struct event_base *base, struct event *ev)
+ {
+ EVENT_BASE_ASSERT_LOCKED(base);
+ if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_ACTIVE))) {
+ event_errx(1, "%s: %p(fd %d) not on queue %x", __func__,
+ ev, ev->ev_fd, EVLIST_ACTIVE);
+ return;
}
+ DECR_EVENT_COUNT(base, ev);
+ ev->ev_flags &= ~EVLIST_ACTIVE;
+ base->event_count_active--;
+ TAILQ_REMOVE(&base->activequeues[ev->ev_pri],
+ ev, ev_active_next);
}
-
- /* Remove and reinsert 'ev' into the appropriate queue. Only EVLIST_TIMEOUT
- * is supported. */
static void
- event_queue_reinsert(struct event_base *base, struct event *ev, int queue)
+ event_queue_remove_timeout(struct event_base *base, struct event *ev)
{
- if (!(ev->ev_flags & queue)) {
- event_queue_insert(base, ev, queue);
+ EVENT_BASE_ASSERT_LOCKED(base);
+ if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_TIMEOUT))) {
+ event_errx(1, "%s: %p(fd %d) not on queue %x", __func__,
+ ev, ev->ev_fd, EVLIST_TIMEOUT);
return;
}
+ DECR_EVENT_COUNT(base, ev);
+ ev->ev_flags &= ~EVLIST_TIMEOUT;
+
+ if (is_common_timeout(&ev->ev_timeout, base)) {
+ struct common_timeout_list *ctl =
+ get_common_timeout_list(base, &ev->ev_timeout);
+ TAILQ_REMOVE(&ctl->events, ev,
+ ev_timeout_pos.ev_next_with_common_timeout);
+ } else {
+ min_heap_erase(&base->timeheap, ev);
+ }
+ }
- if (queue != EVLIST_TIMEOUT) {
- event_errx(1, "%s: Unsupported queue %x", __func__, queue);
- return; /* unreached */
++/* Remove and reinsert 'ev' into the timeout queue. */
++static void
++event_queue_reinsert_timeout(struct event_base *base, struct event *ev)
++{
++ if (!(ev->ev_flags & EVLIST_TIMEOUT)) {
++ event_queue_insert_timeout(base, ev);
++ return;
+ }
+
+ if (is_common_timeout(&ev->ev_timeout, base)) {
+ struct common_timeout_list *ctl =
+ get_common_timeout_list(base, &ev->ev_timeout);
+ TAILQ_REMOVE(&ctl->events, ev,
+ ev_timeout_pos.ev_next_with_common_timeout);
+ insert_common_timeout_inorder(ctl, ev);
+ } else {
+ min_heap_adjust(&base->timeheap, ev);
+ }
+}
+
/* Add 'ev' to the common timeout list in 'ev'. */
static void
insert_common_timeout_inorder(struct common_timeout_list *ctl,