fdqueue.c revision 6a5bdbbacf4a62adecde52b8f23ebcc4fa2a08b8
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/* ====================================================================
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * The Apache Software License, Version 1.1
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * reserved.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Redistribution and use in source and binary forms, with or without
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun * modification, are permitted provided that the following conditions
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * are met:
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 2. Redistributions in binary form must reproduce the above copyright
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * notice, this list of conditions and the following disclaimer in
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * the documentation and/or other materials provided with the
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen * distribution.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd *
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * 3. The end-user documentation included with the redistribution,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * if any, must include the following acknowledgment:
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * "This product includes software developed by the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * Apache Software Foundation (http://www.apache.org/)."
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Alternately, this acknowledgment may appear in the software itself,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * if and wherever such third-party acknowledgments normally appear.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * 4. The names "Apache" and "Apache Software Foundation" must
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * not be used to endorse or promote products derived from this
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * software without prior written permission. For written
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * permission, please contact apache@apache.org.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen * 5. Products derived from this software may not be called "Apache",
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * nor may "Apache" appear in their name, without prior written
a166215fba9f76030a979c81f95becff52f5aeefrbowen * permission of the Apache Software Foundation.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * SUCH DAMAGE.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * ====================================================================
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *
a166215fba9f76030a979c81f95becff52f5aeefrbowen * This software consists of voluntary contributions made by many
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * individuals on behalf of the Apache Software Foundation. For more
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * information on the Apache Software Foundation, please see
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * <http://www.apache.org/>.
a166215fba9f76030a979c81f95becff52f5aeefrbowen *
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Portions of this software are based upon public domain software
dfc5f686a6ac416a480f0281c9ff0a751013fcf2nilgun * originally written at the National Center for Supercomputing Applications,
a166215fba9f76030a979c81f95becff52f5aeefrbowen * University of Illinois, Urbana-Champaign.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
a166215fba9f76030a979c81f95becff52f5aeefrbowen#include "fdqueue.h"
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/**
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Detects when the fd_queue_t is full. This utility function is expected
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * to be called from within critical sections, and is not threadsafe.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony#define ap_queue_full(queue) ((queue)->tail == (queue)->bounds)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/**
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Detects when the fd_queue_t is empty. This utility function is expected
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * to be called from within critical sections, and is not threadsafe.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony#define ap_queue_empty(queue) ((queue)->tail == 0)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/**
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Callback routine that is called to destroy this
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * fd_queue_t when its pool is destroyed.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonystatic apr_status_t ap_queue_destroy(void *data)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony{
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony fd_queue_t *queue = data;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* Ignore errors here, we can't do anything about them anyway.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * XXX: We should at least try to signal an error here, it is
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * indicative of a programmer error. -aaron */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_thread_cond_destroy(queue->not_empty);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_thread_cond_destroy(queue->not_full);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_thread_mutex_destroy(queue->one_big_mutex);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony return APR_SUCCESS;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony}
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun/**
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun * Initialize the fd_queue_t.
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun */
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgunapr_status_t ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a)
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun{
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun int i;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun apr_status_t rv;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun if ((rv = apr_thread_mutex_create(&queue->one_big_mutex,
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun APR_THREAD_MUTEX_DEFAULT, a)) != APR_SUCCESS) {
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun return rv;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if ((rv = apr_thread_cond_create(&queue->not_empty, a)) != APR_SUCCESS) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony return rv;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if ((rv = apr_thread_cond_create(&queue->not_full, a)) != APR_SUCCESS) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony return rv;
a166215fba9f76030a979c81f95becff52f5aeefrbowen }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony queue->tail = 0;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
a166215fba9f76030a979c81f95becff52f5aeefrbowen queue->bounds = queue_capacity;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony /* Set all the sockets in the queue to NULL */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony for (i = 0; i < queue_capacity; ++i)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony queue->data[i].sd = NULL;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
a166215fba9f76030a979c81f95becff52f5aeefrbowen queue->recycled_pools = apr_palloc(a,
a166215fba9f76030a979c81f95becff52f5aeefrbowen queue_capacity * sizeof(apr_pool_t *));
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony queue->num_recycled = 0;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_pool_cleanup_register(a, queue, ap_queue_destroy, apr_pool_cleanup_null);
a166215fba9f76030a979c81f95becff52f5aeefrbowen
a166215fba9f76030a979c81f95becff52f5aeefrbowen return APR_SUCCESS;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony}
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony/**
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Push a new socket onto the queue. Blocks if the queue is full. Once
a166215fba9f76030a979c81f95becff52f5aeefrbowen * the push operation has completed, it signals other threads waiting
a166215fba9f76030a979c81f95becff52f5aeefrbowen * in apr_queue_pop() that they may continue consuming sockets.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony */
a166215fba9f76030a979c81f95becff52f5aeefrbowenapr_status_t ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p,
a166215fba9f76030a979c81f95becff52f5aeefrbowen apr_pool_t **recycled_pool)
a166215fba9f76030a979c81f95becff52f5aeefrbowen{
a166215fba9f76030a979c81f95becff52f5aeefrbowen fd_queue_elem_t *elem;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_status_t rv;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *recycled_pool = NULL;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony return rv;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
a166215fba9f76030a979c81f95becff52f5aeefrbowen AP_DEBUG_ASSERT(!queue->terminated);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony while (ap_queue_full(queue)) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_thread_cond_wait(queue->not_full, queue->one_big_mutex);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun elem = &queue->data[queue->tail++];
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun elem->sd = sd;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun elem->p = p;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun if (queue->num_recycled != 0) {
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun *recycled_pool = queue->recycled_pools[--queue->num_recycled];
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun }
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun apr_thread_cond_signal(queue->not_empty);
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun return rv;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun }
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun return APR_SUCCESS;
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun}
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun/**
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Retrieves the next available socket from the queue. If there are no
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * sockets available, it will block until one becomes available.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * Once retrieved, the socket is placed into the address specified by
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony * 'sd'.
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony */
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctonyapr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p,
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_pool_t *recycled_pool)
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony{
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony fd_queue_elem_t *elem;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_status_t rv;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if (recycled_pool) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony apr_pool_destroy(recycled_pool);
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony return rv;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony }
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if (recycled_pool) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony if (queue->num_recycled < queue->bounds) {
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony queue->recycled_pools[queue->num_recycled++] = recycled_pool;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony }
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung else {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh apr_pool_destroy(recycled_pool);
ba543b319188dc1887607f6d59feddc00e38eee2humbedooh }
0d0ba3a410038e179b695446bb149cce6264e0abnd }
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd /* Keep waiting until we wake up and find that the queue is not empty. */
0d0ba3a410038e179b695446bb149cce6264e0abnd if (ap_queue_empty(queue)) {
0d0ba3a410038e179b695446bb149cce6264e0abnd if (!queue->terminated) {
0d0ba3a410038e179b695446bb149cce6264e0abnd apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
0d0ba3a410038e179b695446bb149cce6264e0abnd }
0d0ba3a410038e179b695446bb149cce6264e0abnd /* If we wake up and it's still empty, then we were interrupted */
0d0ba3a410038e179b695446bb149cce6264e0abnd if (ap_queue_empty(queue)) {
0d0ba3a410038e179b695446bb149cce6264e0abnd if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
0d0ba3a410038e179b695446bb149cce6264e0abnd return rv;
0d0ba3a410038e179b695446bb149cce6264e0abnd }
0d0ba3a410038e179b695446bb149cce6264e0abnd if (queue->terminated) {
0d0ba3a410038e179b695446bb149cce6264e0abnd return APR_EOF; /* no more elements ever again */
0d0ba3a410038e179b695446bb149cce6264e0abnd }
0d0ba3a410038e179b695446bb149cce6264e0abnd else {
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh return APR_EINTR;
5effc8b39fae5cd169d17f342bfc265705840014rbowen }
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen }
0d0ba3a410038e179b695446bb149cce6264e0abnd }
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd elem = &queue->data[--queue->tail];
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd *sd = elem->sd;
0f6bc9e2c8229996a73fb57ec6c45841346ebcb1pctony *p = elem->p;
elem->sd = NULL;
elem->p = NULL;
/* signal not_full if we were full before this pop */
if (queue->tail == queue->bounds - 1) {
apr_thread_cond_signal(queue->not_full);
}
if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
return APR_SUCCESS;
}
apr_status_t ap_queue_interrupt_all(fd_queue_t *queue)
{
apr_status_t rv;
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
apr_thread_cond_broadcast(queue->not_empty);
/* We shouldn't have multiple threads sitting in not_full, but
* broadcast just in case. */
apr_thread_cond_broadcast(queue->not_full);
if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
return APR_SUCCESS;
}
apr_status_t ap_queue_term(fd_queue_t *queue)
{
apr_status_t rv;
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
/* we must hold one_big_mutex when setting this... otherwise,
* we could end up setting it and waking everybody up just after a
* would-be popper checks it but right before they block
*/
queue->terminated = 1;
if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}
return ap_queue_interrupt_all(queue);
}