apr_thread_cond_destroy(queue->not_full);
apr_thread_mutex_destroy(queue->one_big_mutex);
- return FD_QUEUE_SUCCESS;
+ return APR_SUCCESS;
}
/**
* Initialize the fd_queue_t.
*/
-int ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a)
+apr_status_t ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a)
{
int i;
+ apr_status_t rv;
- /* FIXME: APRize these return values. */
- if (apr_thread_mutex_create(&queue->one_big_mutex,
- APR_THREAD_MUTEX_DEFAULT, a) != APR_SUCCESS)
- return FD_QUEUE_FAILURE;
- if (apr_thread_cond_create(&queue->not_empty, a) != APR_SUCCESS)
- return FD_QUEUE_FAILURE;
- if (apr_thread_cond_create(&queue->not_full, a) != APR_SUCCESS)
- return FD_QUEUE_FAILURE;
+ if ((rv = apr_thread_mutex_create(&queue->one_big_mutex,
+ APR_THREAD_MUTEX_DEFAULT, a)) != APR_SUCCESS) {
+ return rv;
+ }
+ if ((rv = apr_thread_cond_create(&queue->not_empty, a)) != APR_SUCCESS) {
+ return rv;
+ }
+ if ((rv = apr_thread_cond_create(&queue->not_full, a)) != APR_SUCCESS) {
+ return rv;
+ }
queue->tail = 0;
queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
apr_pool_cleanup_register(a, queue, ap_queue_destroy, apr_pool_cleanup_null);
- return FD_QUEUE_SUCCESS;
+ return APR_SUCCESS;
}
/**
* the push operation has completed, it signals other threads waiting
* in apr_queue_pop() that they may continue consuming sockets.
*/
-int ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p,
- apr_pool_t **recycled_pool)
+apr_status_t ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p,
+ apr_pool_t **recycled_pool)
{
fd_queue_elem_t *elem;
+ apr_status_t rv;
*recycled_pool = NULL;
- if (apr_thread_mutex_lock(queue->one_big_mutex) != APR_SUCCESS) {
- return FD_QUEUE_FAILURE;
+ if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
+ return rv;
}
while (ap_queue_full(queue)) {
apr_thread_cond_signal(queue->not_empty);
- if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
- return FD_QUEUE_FAILURE;
+ if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
+ return rv;
}
- return FD_QUEUE_SUCCESS;
+ return APR_SUCCESS;
}
/**
apr_pool_t *recycled_pool)
{
fd_queue_elem_t *elem;
+ apr_status_t rv;
- if (apr_thread_mutex_lock(queue->one_big_mutex) != APR_SUCCESS) {
+ if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
if (recycled_pool) {
apr_pool_destroy(recycled_pool);
}
- return FD_QUEUE_FAILURE;
+ return rv;
}
if (recycled_pool) {
apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
/* If we wake up and it's still empty, then we were interrupted */
if (ap_queue_empty(queue)) {
- if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
- return FD_QUEUE_FAILURE;
+ if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
+ return rv;
}
- return FD_QUEUE_EINTR;
+ return APR_EINTR;
}
}
apr_thread_cond_signal(queue->not_full);
}
- if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
- return FD_QUEUE_FAILURE;
+ 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)
{
- if (apr_thread_mutex_lock(queue->one_big_mutex) != APR_SUCCESS) {
- return FD_QUEUE_FAILURE;
+ 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 (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
- return FD_QUEUE_FAILURE;
+ if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
+ return rv;
}
- return FD_QUEUE_SUCCESS;
+ return APR_SUCCESS;
}
#endif
#include <apr_errno.h>
-#define FD_QUEUE_SUCCESS 0
-#define FD_QUEUE_FAILURE -1 /* Needs to be an invalid file descriptor because
- of queue_pop semantics */
-#define FD_QUEUE_EINTR APR_EINTR
-
struct fd_queue_elem_t {
apr_socket_t *sd;
apr_pool_t *p;
};
typedef struct fd_queue_t fd_queue_t;
-/* FIXME: APRize these -- return values should be apr_status_t */
-int ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a);
-int ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p,
- apr_pool_t **recycled_pool);
+apr_status_t ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a);
+apr_status_t ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p,
+ apr_pool_t **recycled_pool);
apr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p,
apr_pool_t *recycled_pool);
apr_status_t ap_queue_interrupt_all(fd_queue_t *queue);
* socket to a worker
*/
apr_socket_close(csd);
- ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ap_server_conf,
- "ap_queue_push failed with error code %d",
- rv);
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf,
+ "ap_queue_push failed");
}
}
}
rv = ap_queue_pop(worker_queue, &csd, &ptrans, last_ptrans);
last_ptrans = NULL;
- /* We get FD_QUEUE_EINTR whenever ap_queue_pop() has been interrupted
+ /* We get APR_EINTR whenever ap_queue_pop() has been interrupted
* from an explicit call to ap_queue_interrupt_all(). This allows
* us to unblock threads stuck in ap_queue_pop() when a shutdown
* is pending. */
- if (rv == FD_QUEUE_EINTR || !csd) {
+ if (rv == APR_EINTR || !csd) {
continue;
}
process_socket(ptrans, csd, process_slot, thread_slot);
/* We must create the fd queues before we start up the listener
* and worker threads. */
worker_queue = apr_pcalloc(pchild, sizeof(*worker_queue));
- ap_queue_init(worker_queue, ap_threads_per_child, pchild);
+ rv = ap_queue_init(worker_queue, ap_threads_per_child, pchild);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ALERT, rv, ap_server_conf,
+ "ap_queue_init() failed");
+ clean_child_exit(APEXIT_CHILDFATAL);
+ }
my_info = (proc_info *)malloc(sizeof(proc_info));
my_info->pid = my_child_num;
"apr_thread_create: unable to create worker thread");
/* In case system resources are maxxed out, we don't want
* Apache running away with the CPU trying to fork over and
- * over and over again if we exit. */
+ * over and over again if we exit.
+ * XXX Jeff doesn't see how Apache is going to try to fork again since
+ * the exit code is APEXIT_CHILDFATAL
+ */
apr_sleep(10 * APR_USEC_PER_SEC);
clean_child_exit(APEXIT_CHILDFATAL);
}