]> granicus.if.org Git - apache/commitdiff
Revert an old (~10yr) change to the fd Q; move back to
authorJim Jagielski <jim@apache.org>
Thu, 27 Jan 2011 19:34:38 +0000 (19:34 +0000)
committerJim Jagielski <jim@apache.org>
Thu, 27 Jan 2011 19:34:38 +0000 (19:34 +0000)
FIFO rather than LIFO, for more consistent performance
so that older requests don't suffer

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

server/mpm/event/fdqueue.c
server/mpm/event/fdqueue.h
server/mpm/worker/fdqueue.c
server/mpm/worker/fdqueue.h

index 10015b7d39d705f3b9b9a4772166e44f69e6b877..c1dbda1ee526d4296f3b12c707feb4549bf75467 100644 (file)
@@ -310,6 +310,8 @@ apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
     queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
     queue->bounds = queue_capacity;
     queue->nelts = 0;
+    queue->in = 0;
+    queue->out = 0;
 
     /* Set all the sockets in the queue to NULL */
     for (i = 0; i < queue_capacity; ++i)
@@ -340,7 +342,10 @@ apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
     AP_DEBUG_ASSERT(!queue->terminated);
     AP_DEBUG_ASSERT(!ap_queue_full(queue));
 
-    elem = &queue->data[queue->nelts];
+    elem = &queue->data[queue->in];
+    queue->in++;
+    if (queue->in >= queue->bounds)
+        queue->in -= queue->bounds;
     elem->sd = sd;
     elem->cs = cs;
     elem->p = p;
@@ -420,7 +425,11 @@ apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd,
         APR_RING_REMOVE(*te_out, link);
     }
     else {
-        elem = &queue->data[--queue->nelts];
+        elem = &queue->data[queue->out];
+        queue->out++;
+        if (queue->out >= queue->bounds)
+            queue->out -= queue->bounds;
+        queue->nelts--;
         *sd = elem->sd;
         *cs = elem->cs;
         *p = elem->p;
index 9482d71b0c4a52f36c3cfbbbecb32f7545a802fd..fbe120b8db8a4f69d2bdf80912dee3302970705d 100644 (file)
@@ -70,8 +70,10 @@ struct fd_queue_t
 {
     APR_RING_HEAD(timers_t, timer_event_t) timers;
     fd_queue_elem_t *data;
-    int nelts;
-    int bounds;
+    unsigned int nelts;
+    unsigned int bounds;
+    unsigned int in;
+    unsigned int out;
     apr_thread_mutex_t *one_big_mutex;
     apr_thread_cond_t *not_empty;
     int terminated;
index 49e53032ceb5a13f415066627cc1a7ffe5f26d38..fe5881b4ce833856c44a2e52bf151dff22536ceb 100644 (file)
@@ -284,6 +284,8 @@ apr_status_t ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a)
     queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
     queue->bounds = queue_capacity;
     queue->nelts = 0;
+    queue->in = 0;
+    queue->out = 0;
 
     /* Set all the sockets in the queue to NULL */
     for (i = 0; i < queue_capacity; ++i)
@@ -312,7 +314,10 @@ apr_status_t ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p)
     AP_DEBUG_ASSERT(!queue->terminated);
     AP_DEBUG_ASSERT(!ap_queue_full(queue));
 
-    elem = &queue->data[queue->nelts];
+    elem = &queue->data[queue->in];
+    queue->in++;
+    if (queue->in >= queue->bounds)
+        queue->in -= queue->bounds;
     elem->sd = sd;
     elem->p = p;
     queue->nelts++;
@@ -361,7 +366,11 @@ apr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p)
         }
     }
 
-    elem = &queue->data[--queue->nelts];
+    elem = &queue->data[queue->out];
+    queue->out++;
+    if (queue->out >= queue->bounds)
+        queue->out -= queue->bounds;
+    queue->nelts--;
     *sd = elem->sd;
     *p = elem->p;
 #ifdef AP_DEBUG
index 7de082a03838a2a9df0da3390263241699d2fbaf..1d48a1a82686bfa77c63e237c4584a45185a2f5e 100644 (file)
@@ -55,8 +55,10 @@ typedef struct fd_queue_elem_t fd_queue_elem_t;
 
 struct fd_queue_t {
     fd_queue_elem_t    *data;
-    int                 nelts;
-    int                 bounds;
+    unsigned int       nelts;
+    unsigned int       bounds;
+    unsigned int       in;
+    unsigned int       out;
     apr_thread_mutex_t *one_big_mutex;
     apr_thread_cond_t  *not_empty;
     int                 terminated;