/* 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 */
- pthread_cond_destroy(&queue->not_empty);
- pthread_cond_destroy(&queue->not_full);
- pthread_mutex_destroy(&queue->one_big_mutex);
+ apr_thread_cond_destroy(queue->not_empty);
+ apr_thread_cond_destroy(queue->not_full);
+ apr_thread_mutex_destroy(queue->one_big_mutex);
return FD_QUEUE_SUCCESS;
}
{
int i;
- if (pthread_mutex_init(&queue->one_big_mutex, NULL) != 0)
+ /* 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 (pthread_cond_init(&queue->not_empty, NULL) != 0)
+ if (apr_thread_cond_create(&queue->not_empty, a) != APR_SUCCESS)
return FD_QUEUE_FAILURE;
- if (pthread_cond_init(&queue->not_full, NULL) != 0)
+ if (apr_thread_cond_create(&queue->not_full, a) != APR_SUCCESS)
return FD_QUEUE_FAILURE;
queue->tail = 0;
{
fd_queue_elem_t *elem;
- if (pthread_mutex_lock(&queue->one_big_mutex) != 0) {
+ if (apr_thread_mutex_lock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
while (ap_queue_full(queue)) {
- pthread_cond_wait(&queue->not_full, &queue->one_big_mutex);
+ apr_thread_cond_wait(queue->not_full, queue->one_big_mutex);
}
elem = &queue->data[queue->tail++];
elem->sd = sd;
elem->p = p;
- pthread_cond_signal(&queue->not_empty);
+ apr_thread_cond_signal(queue->not_empty);
- if (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
+ if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
{
fd_queue_elem_t *elem;
- if (pthread_mutex_lock(&queue->one_big_mutex) != 0) {
+ if (apr_thread_mutex_lock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
/* Keep waiting until we wake up and find that the queue is not empty. */
if (ap_queue_empty(queue)) {
- pthread_cond_wait(&queue->not_empty, &queue->one_big_mutex);
+ 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 (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
+ if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
return FD_QUEUE_EINTR;
/* signal not_full if we were full before this pop */
if (queue->tail == queue->bounds - 1) {
- pthread_cond_signal(&queue->not_full);
+ apr_thread_cond_signal(queue->not_full);
}
- if (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
+ if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
apr_status_t ap_queue_interrupt_all(fd_queue_t *queue)
{
- if (pthread_mutex_lock(&queue->one_big_mutex) != 0) {
+ if (apr_thread_mutex_lock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
- pthread_cond_broadcast(&queue->not_empty);
+ apr_thread_cond_broadcast(queue->not_empty);
/* We shouldn't have multiple threads sitting in not_full, but
* broadcast just in case. */
- pthread_cond_broadcast(&queue->not_full);
- if (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
+ apr_thread_cond_broadcast(queue->not_full);
+ if (apr_thread_mutex_unlock(queue->one_big_mutex) != APR_SUCCESS) {
return FD_QUEUE_FAILURE;
}
return FD_QUEUE_SUCCESS;
#if APR_HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include <pthread.h>
+#include <apr_thread_mutex.h>
+#include <apr_thread_cond.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <apr_errno.h>
typedef struct fd_queue_elem_t fd_queue_elem_t;
struct fd_queue_t {
- int tail;
- fd_queue_elem_t *data;
- int bounds;
- int blanks;
- pthread_mutex_t one_big_mutex;
- pthread_cond_t not_empty;
- pthread_cond_t not_full;
- int cancel_state;
+ int tail;
+ fd_queue_elem_t *data;
+ int bounds;
+ int blanks;
+ apr_thread_mutex_t *one_big_mutex;
+ apr_thread_cond_t *not_empty;
+ apr_thread_cond_t *not_full;
+ int cancel_state;
};
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_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p);