]> granicus.if.org Git - libevent/commitdiff
faster insertion of timeouts; ensure uniqueness in RB-tree compare function
authorNiels Provos <provos@gmail.com>
Sat, 27 Mar 2004 17:42:49 +0000 (17:42 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 27 Mar 2004 17:42:49 +0000 (17:42 +0000)
svn:r97

event.c

diff --git a/event.c b/event.c
index ed8c36320b7b3904c5dd450ad75cc9f34e488432..86a17e6d46a5fa951a9274ed92c7f398c5f40fb2 100644 (file)
--- a/event.c
+++ b/event.c
@@ -115,7 +115,6 @@ int event_gotterm;          /* Set to terminate loop */
 void           event_queue_insert(struct event *, int);
 void           event_queue_remove(struct event *, int);
 int            event_haveevents(void);
-void           timeout_insert(struct event *);
 
 static void    event_process_active(void);
 
@@ -132,6 +131,10 @@ compare(struct event *a, struct event *b)
                return (-1);
        else if (timercmp(&a->ev_timeout, &b->ev_timeout, >))
                return (1);
+       if (a < b)
+               return (-1);
+       if (a > b)
+               return (1);
        return (0);
 }
 
@@ -566,31 +569,6 @@ timeout_process(void)
        }
 }
 
-void
-timeout_insert(struct event *ev)
-{
-       struct event *tmp;
-
-       tmp = RB_FIND(event_tree, &timetree, ev);
-
-       if (tmp != NULL) {
-               struct timeval tv;
-               struct timeval add = {0,1};
-
-               /* Find unique time */
-               tv = ev->ev_timeout;
-               do {
-                       timeradd(&tv, &add, &tv);
-                       tmp = RB_NEXT(event_tree, &timetree, tmp);
-               } while (tmp != NULL && timercmp(&tmp->ev_timeout, &tv, ==));
-
-               ev->ev_timeout = tv;
-       }
-
-       tmp = RB_INSERT(event_tree, &timetree, ev);
-       assert(tmp == NULL);
-}
-
 void
 event_queue_remove(struct event *ev, int queue)
 {
@@ -632,9 +610,11 @@ event_queue_insert(struct event *ev, int queue)
        case EVLIST_SIGNAL:
                TAILQ_INSERT_TAIL(&signalqueue, ev, ev_signal_next);
                break;
-       case EVLIST_TIMEOUT:
-               timeout_insert(ev);
+       case EVLIST_TIMEOUT: {
+               struct event *tmp = RB_INSERT(event_tree, &timetree, ev);
+               assert(tmp == NULL);
                break;
+       }
        case EVLIST_INSERTED:
                TAILQ_INSERT_TAIL(&eventqueue, ev, ev_next);
                break;