]> granicus.if.org Git - apache/commitdiff
mpm_event: follow up to r1666468.
authorYann Ylavic <ylavic@apache.org>
Sat, 14 Mar 2015 00:06:21 +0000 (00:06 +0000)
committerYann Ylavic <ylavic@apache.org>
Sat, 14 Mar 2015 00:06:21 +0000 (00:06 +0000)
We only need one compare function for add semantic with apr_skiplist_insert()
and unique timers (pointers). It also should work with apr_skiplist_remove()
and apr_skiplist_find(), be they used some day.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1666618 13f79535-47bb-0310-9956-ffa450edef68

server/mpm/event/event.c

index 595105c510a09b4a1210d78cf290119b7aa8ba12..fa5a07a173f7936344de698af716b6fb858aae65 100644 (file)
@@ -1454,30 +1454,18 @@ static APR_RING_HEAD(timer_free_ring_t, timer_event_t) timer_free_ring;
 
 static apr_skiplist *timer_skiplist;
 
-static int indexing_comp(void *a, void *b)
+static int timer_comp(void *a, void *b)
 {
-    apr_time_t t1 = (apr_time_t) (((timer_event_t *) a)->when);
-    apr_time_t t2 = (apr_time_t) (((timer_event_t *) b)->when);
-    AP_DEBUG_ASSERT(t1);
-    AP_DEBUG_ASSERT(t2);
-    return ((t1 < t2) ? -1 : (t1 > t2));
-}
-
-static int indexing_compk(void *ac, void *b)
-{
-    apr_time_t *t1 = (apr_time_t *) ac;
-    apr_time_t t2 = (apr_time_t) (((timer_event_t *) b)->when);
-    AP_DEBUG_ASSERT(t2);
-    return ((*t1 < t2) ? -1 : (*t1 > t2));
-}
-
-static int indexing_add_comp(void *a, void *b)
-{
-    apr_time_t t1 = (apr_time_t) (((timer_event_t *) a)->when);
-    apr_time_t t2 = (apr_time_t) (((timer_event_t *) b)->when);
-    AP_DEBUG_ASSERT(t1);
-    AP_DEBUG_ASSERT(t2);
-    return ((t1 < t2) ? -1 : 1);
+    if (a != b) {
+        apr_time_t t1 = (apr_time_t) (((timer_event_t *) a)->when);
+        apr_time_t t2 = (apr_time_t) (((timer_event_t *) b)->when);
+        AP_DEBUG_ASSERT(t1);
+        AP_DEBUG_ASSERT(t2);
+        return ((t1 < t2) ? -1 : 1);
+    }
+    else {
+        return 0;
+    }
 }
 
 static apr_thread_mutex_t *g_timer_skiplist_mtx;
@@ -1510,7 +1498,11 @@ static timer_event_t * event_get_timer_event(apr_time_t t,
 
     if (insert) { 
         /* Okay, add sorted by when.. */
-        apr_skiplist_insert_compare(timer_skiplist, te, indexing_add_comp);
+#ifdef AP_DEBUG
+        ap_assert(apr_skiplist_insert(timer_skiplist, te));
+#else
+        apr_skiplist_insert(timer_skiplist, te);
+#endif
     }
     apr_thread_mutex_unlock(g_timer_skiplist_mtx);
 
@@ -2538,7 +2530,7 @@ static void child_main(int child_num_arg, int child_bucket)
     APR_RING_INIT(&timer_free_ring, timer_event_t, link);
     apr_pool_create(&pskip, pchild);
     apr_skiplist_init(&timer_skiplist, pskip);
-    apr_skiplist_set_compare(timer_skiplist, indexing_comp, indexing_compk);
+    apr_skiplist_set_compare(timer_skiplist, timer_comp, timer_comp);
     ap_run_child_init(pchild, ap_server_conf);
 
     /* done with init critical section */