jerenkrantz 2002/12/23 12:31:25
Modified: misc apr_queue.c
Log:
Style police have been recalled from hibernation.
*No code changes*
Revision Changes Path
1.6 +35 -37 apr-util/misc/apr_queue.c
Index: apr_queue.c
===================================================================
RCS file: /home/cvs/apr-util/misc/apr_queue.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -u -r1.5 -r1.6
--- apr_queue.c 22 Dec 2002 21:53:24 -0000 1.5
+++ apr_queue.c 23 Dec 2002 20:31:25 -0000 1.6
@@ -92,7 +92,6 @@
};
#ifdef QUEUE_DEBUG
-
static void Q_DBG(char*msg, apr_queue_t *q) {
fprintf(stderr, "%ld\t#%d in %d out %d\t%s\n",
apr_os_thread_current(),
@@ -104,8 +103,6 @@
#define Q_DBG(x,y)
#endif
-
-
/**
* Detects when the apr_queue_t is full. This utility function is expected
* to be called from within critical sections, and is not threadsafe.
@@ -118,7 +115,6 @@
*/
#define apr_queue_empty(queue) ((queue)->nelts == 0)
-
/**
* Callback routine that is called to destroy this
* apr_queue_t when its pool is destroyed.
@@ -145,18 +141,19 @@
{
apr_status_t rv;
apr_queue_t *queue;
- queue = apr_palloc(a, sizeof( apr_queue_t ));
+ queue = apr_palloc(a, sizeof(apr_queue_t));
*q = queue;
+ /* nested doesn't work ;( */
rv = apr_thread_mutex_create(&queue->one_big_mutex,
- APR_THREAD_MUTEX_UNNESTED, /* nested
doesn't work ;( */
+ APR_THREAD_MUTEX_UNNESTED,
a);
if (rv != APR_SUCCESS) {
return rv;
}
rv = apr_thread_cond_create(&queue->not_empty, a);
- if (rv!= APR_SUCCESS) {
+ if (rv != APR_SUCCESS) {
return rv;
}
@@ -173,10 +170,7 @@
queue->out = 0;
queue->terminated = 0;
- apr_pool_cleanup_register(a,
- queue,
- queue_destroy,
- apr_pool_cleanup_null);
+ apr_pool_cleanup_register(a, queue, queue_destroy,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
@@ -189,7 +183,8 @@
APU_DECLARE(apr_status_t) apr_queue_push(apr_queue_t *queue, void *data)
{
apr_status_t rv;
- int need_signal=0;
+ int need_signal = 0;
+
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}
@@ -209,7 +204,7 @@
}
/* If we wake up and it's still empty, then we were interrupted */
if (apr_queue_full(queue)) {
- Q_DBG( "queue full (intr)", queue);
+ Q_DBG("queue full (intr)", queue);
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
@@ -225,17 +220,17 @@
/* if we were empty then signal that we aren't */
if (apr_queue_empty(queue)) {
- need_signal=1;
+ need_signal = 1;
}
queue->data[queue->in] = data;
- queue->in = (queue->in +1) % queue->bounds ;
+ queue->in = (queue->in + 1) % queue->bounds;
queue->nelts++;
- if ( need_signal == 1 ) {
- Q_DBG( "sig !empty", queue);
- rv = apr_thread_cond_signal(queue->not_empty);
- if ( rv != APR_SUCCESS) {
+ if (need_signal == 1) {
+ Q_DBG("sig !empty", queue);
+ rv = apr_thread_cond_signal(queue->not_empty);
+ if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
@@ -244,6 +239,7 @@
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
+
/**
* Push new data onto the queue. Blocks if the queue is full. Once
* the push operation has completed, it signals other threads waiting
@@ -252,7 +248,7 @@
APU_DECLARE(apr_status_t) apr_queue_trypush(apr_queue_t *queue, void *data)
{
apr_status_t rv;
- int need_signal=0;
+ int need_signal = 0;
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
}
@@ -269,17 +265,17 @@
/* if we were empty then signal that we aren't */
if (apr_queue_empty(queue)) {
- need_signal=1;
+ need_signal = 1;
}
queue->data[queue->in] = data;
- queue->in = (queue->in +1) % queue->bounds ;
+ queue->in = (queue->in + 1) % queue->bounds;
queue->nelts++;
- if ( need_signal == 1 ) {
- Q_DBG( "sig !empty", queue);
+ if (need_signal == 1) {
+ Q_DBG("sig !empty", queue);
rv = apr_thread_cond_signal(queue->not_empty);
- if ( rv != APR_SUCCESS) {
+ if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
@@ -288,12 +284,14 @@
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
+
/**
* not thread safe
*/
APU_DECLARE(int) apr_queue_size(apr_queue_t *queue) {
return queue->nelts;
}
+
/**
* Retrieves the next item from the queue. If there are no
* items available, it will block until one becomes available.
@@ -303,7 +301,7 @@
APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data)
{
apr_status_t rv;
- int need_signal=0;
+ int need_signal = 0;
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
@@ -325,7 +323,7 @@
}
/* If we wake up and it's still empty, then we were interrupted */
if (apr_queue_empty(queue)) {
- Q_DBG( "queue empty (intr)", queue);
+ Q_DBG("queue empty (intr)", queue);
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
if (rv != APR_SUCCESS) {
return rv;
@@ -339,17 +337,17 @@
}
}
if (apr_queue_full(queue)) {
- need_signal =1;
+ need_signal = 1;
}
*data = &queue->data[queue->out];
queue->nelts--;
queue->out = (queue->out + 1) % queue->bounds;
- if ( need_signal == 1 ) {
- Q_DBG( "signal !full", queue);
+ if (need_signal == 1) {
+ Q_DBG("signal !full", queue);
rv = apr_thread_cond_signal(queue->not_full);
- if ( rv != APR_SUCCESS) {
+ if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
@@ -368,7 +366,7 @@
APU_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data)
{
apr_status_t rv;
- int need_signal=0;
+ int need_signal = 0;
if (queue->terminated) {
return APR_EOF; /* no more elements ever again */
@@ -385,17 +383,17 @@
return APR_EAGAIN;
}
if (apr_queue_full(queue)) {
- need_signal =1;
+ need_signal = 1;
}
*data = &queue->data[queue->out];
queue->nelts--;
queue->out = (queue->out + 1) % queue->bounds;
- if ( need_signal == 1 ) {
- Q_DBG( "signal !full", queue);
+ if (need_signal == 1) {
+ Q_DBG("signal !full", queue);
rv = apr_thread_cond_signal(queue->not_full);
- if ( rv != APR_SUCCESS) {
+ if (rv != APR_SUCCESS) {
apr_thread_mutex_unlock(queue->one_big_mutex);
return rv;
}
@@ -408,7 +406,7 @@
APU_DECLARE(apr_status_t) apr_queue_interrupt_all(apr_queue_t *queue)
{
apr_status_t rv;
- Q_DBG( "intr all", queue);
+ Q_DBG("intr all", queue);
if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
return rv;
}