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
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)
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;
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;
{
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;
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)
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++;
}
}
- 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
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;