fdqueue.c revision 0696197a54f186a65abacba1037f6fbe0cb975a1
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "fdqueue.h"
#include "apr_atomic.h"
typedef struct recycled_pool {
struct recycled_pool *next;
struct fd_queue_info_t {
int terminated;
int max_idlers;
};
{
/* Clean up any pools in the recycled list */
for (;;) {
if (first_pool == NULL) {
break;
}
first_pool) == first_pool) {
}
}
return APR_SUCCESS;
}
{
pool);
if (rv != APR_SUCCESS) {
return rv;
}
if (rv != APR_SUCCESS) {
return rv;
}
*queue_info = qi;
return APR_SUCCESS;
}
{
int prev_idlers;
/* If we have been given a pool to recycle, atomically link
* it into the queue_info's list of recycled pools
*/
if (pool_to_recycle) {
struct recycled_pool *new_recycle;
sizeof(*new_recycle));
for (;;) {
new_recycle->next) {
break;
}
}
}
/* Atomically increment the count of idle workers */
for (;;) {
prev_idlers) == prev_idlers) {
break;
}
}
/* If this thread just made the idle worker count nonzero,
* wake up the listener. */
if (prev_idlers == 0) {
if (rv != APR_SUCCESS) {
return rv;
}
if (rv != APR_SUCCESS) {
return rv;
}
if (rv != APR_SUCCESS) {
return rv;
}
}
return APR_SUCCESS;
}
{
*recycled_pool = NULL;
/* Block if the count of idle workers is zero */
if (queue_info->idlers == 0) {
if (rv != APR_SUCCESS) {
return rv;
}
/* Re-check the idle worker count to guard against a
* race condition. Now that we're in the mutex-protected
* region, one of two things may have happened:
* - If the idle worker count is still zero, the
* workers are all still busy, so it's safe to
* block on a condition variable.
* - If the idle worker count is nonzero, then a
* worker has become idle since the first check
* of queue_info->idlers above. It's possible
* that the worker has also signaled the condition
* variable--and if so, the listener missed it
* because it wasn't yet blocked on the condition
* variable. But if the idle worker count is
* now nonzero, it's safe for this function to
* return immediately.
*/
if (queue_info->idlers == 0) {
if (rv != APR_SUCCESS) {
if (rv2 != APR_SUCCESS) {
return rv2;
}
return rv;
}
}
if (rv != APR_SUCCESS) {
return rv;
}
}
/* Atomically decrement the idle worker count */
/* Atomically pop a pool from the recycled list */
for (;;) {
if (first_pool == NULL) {
break;
}
first_pool) == first_pool) {
break;
}
}
if (queue_info->terminated) {
return APR_EOF;
}
else {
return APR_SUCCESS;
}
}
{
if (rv != APR_SUCCESS) {
return rv;
}
}
/**
* 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;
}
/* Set all the sockets in the queue to NULL */
for (i = 0; i < queue_capacity; ++i)
return APR_SUCCESS;
}
/**
* Push a new socket onto the queue.
*
* precondition: ap_queue_info_wait_for_idler has already been called
* to reserve an idle worker thread
*/
{
return rv;
}
elem->p = p;
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'.
*/
{
return rv;
}
/* 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)) {
if (rv != APR_SUCCESS) {
return rv;
}
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}
else {
return APR_EINTR;
}
}
}
*p = elem->p;
#ifdef AP_DEBUG
#endif /* AP_DEBUG */
return rv;
}
{
return rv;
}
}
{
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);
}