]> granicus.if.org Git - libevent/commitdiff
Merge remote-tracking branch 'github/21_split_functions'
authorNick Mathewson <nickm@torproject.org>
Mon, 8 Aug 2011 20:20:53 +0000 (16:20 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 8 Aug 2011 20:20:53 +0000 (16:20 -0400)
Conflicts:
event.c

The conflicts were with the 21_faster_timeout_adj branch, which
added a "reinsert" function that needed to get renamed to
"reinsert_timeout".  Also, some of the code that 21_split_functions
changes got removed by 21_faster_timeout_adj.

1  2 
event.c

diff --cc event.c
index 7ecd0f584714d24bbb2ba18aaa17c33fc061ec17,510914092e6b953c22fbf28e0503cb571492ed8b..cd8a096b2b89117c48a92a189eceea521810686f
+++ b/event.c
@@@ -131,10 -131,12 +131,14 @@@ static inline int event_add_internal(st
      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 *);
@@@ -2090,8 -2070,7 +2090,8 @@@ event_add_internal(struct event *ev, co
                         "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);
@@@ -2439,72 -2418,68 +2439,88 @@@ timeout_process(struct event_base *base
        }
  }
  
- /* 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,