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