Lines Matching refs:queue

48     unsigned int        bounds;/**< max size of queue */
73 #define apr_queue_full(queue) ((queue)->nelts == (queue)->bounds)
79 #define apr_queue_empty(queue) ((queue)->nelts == 0)
87 apr_queue_t *queue = data;
91 apr_thread_cond_destroy(queue->not_empty);
92 apr_thread_cond_destroy(queue->not_full);
93 apr_thread_mutex_destroy(queue->one_big_mutex);
106 apr_queue_t *queue;
107 queue = apr_palloc(a, sizeof(apr_queue_t));
108 *q = queue;
111 rv = apr_thread_mutex_create(&queue->one_big_mutex,
118 rv = apr_thread_cond_create(&queue->not_empty, a);
123 rv = apr_thread_cond_create(&queue->not_full, a);
128 /* Set all the data in the queue to NULL */
129 queue->data = apr_pcalloc(a, queue_capacity * sizeof(void*));
130 queue->bounds = queue_capacity;
131 queue->nelts = 0;
132 queue->in = 0;
133 queue->out = 0;
134 queue->terminated = 0;
135 queue->full_waiters = 0;
136 queue->empty_waiters = 0;
138 apr_pool_cleanup_register(a, queue, queue_destroy, apr_pool_cleanup_null);
144 * Push new data onto the queue. Blocks if the queue is full. Once
148 APU_DECLARE(apr_status_t) apr_queue_push(apr_queue_t *queue, void *data)
152 if (queue->terminated) {
156 rv = apr_thread_mutex_lock(queue->one_big_mutex);
161 if (apr_queue_full(queue)) {
162 if (!queue->terminated) {
163 queue->full_waiters++;
164 rv = apr_thread_cond_wait(queue->not_full, queue->one_big_mutex);
165 queue->full_waiters--;
167 apr_thread_mutex_unlock(queue->one_big_mutex);
172 if (apr_queue_full(queue)) {
173 Q_DBG("queue full (intr)", queue);
174 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
178 if (queue->terminated) {
187 queue->data[queue->in] = data;
188 queue->in++;
189 if (queue->in >= queue->bounds)
190 queue->in -= queue->bounds;
191 queue->nelts++;
193 if (queue->empty_waiters) {
194 Q_DBG("sig !empty", queue);
195 rv = apr_thread_cond_signal(queue->not_empty);
197 apr_thread_mutex_unlock(queue->one_big_mutex);
202 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
207 * Push new data onto the queue. If the queue is full, return APR_EAGAIN. If
211 APU_DECLARE(apr_status_t) apr_queue_trypush(apr_queue_t *queue, void *data)
215 if (queue->terminated) {
219 rv = apr_thread_mutex_lock(queue->one_big_mutex);
224 if (apr_queue_full(queue)) {
225 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
229 queue->data[queue->in] = data;
230 queue->in++;
231 if (queue->in >= queue->bounds)
232 queue->in -= queue->bounds;
233 queue->nelts++;
235 if (queue->empty_waiters) {
236 Q_DBG("sig !empty", queue);
237 rv = apr_thread_cond_signal(queue->not_empty);
239 apr_thread_mutex_unlock(queue->one_big_mutex);
244 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
251 APU_DECLARE(unsigned int) apr_queue_size(apr_queue_t *queue) {
252 return queue->nelts;
256 * Retrieves the next item from the queue. If there are no
261 APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data)
265 if (queue->terminated) {
269 rv = apr_thread_mutex_lock(queue->one_big_mutex);
274 /* Keep waiting until we wake up and find that the queue is not empty. */
275 if (apr_queue_empty(queue)) {
276 if (!queue->terminated) {
277 queue->empty_waiters++;
278 rv = apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
279 queue->empty_waiters--;
281 apr_thread_mutex_unlock(queue->one_big_mutex);
286 if (apr_queue_empty(queue)) {
287 Q_DBG("queue empty (intr)", queue);
288 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
292 if (queue->terminated) {
301 *data = queue->data[queue->out];
302 queue->nelts--;
304 queue->out++;
305 if (queue->out >= queue->bounds)
306 queue->out -= queue->bounds;
307 if (queue->full_waiters) {
308 Q_DBG("signal !full", queue);
309 rv = apr_thread_cond_signal(queue->not_full);
311 apr_thread_mutex_unlock(queue->one_big_mutex);
316 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
321 * Retrieves the next item from the queue. If there are no
325 APU_DECLARE(apr_status_t) apr_queue_trypop(apr_queue_t *queue, void **data)
329 if (queue->terminated) {
333 rv = apr_thread_mutex_lock(queue->one_big_mutex);
338 if (apr_queue_empty(queue)) {
339 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
343 *data = queue->data[queue->out];
344 queue->nelts--;
346 queue->out++;
347 if (queue->out >= queue->bounds)
348 queue->out -= queue->bounds;
349 if (queue->full_waiters) {
350 Q_DBG("signal !full", queue);
351 rv = apr_thread_cond_signal(queue->not_full);
353 apr_thread_mutex_unlock(queue->one_big_mutex);
358 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
362 APU_DECLARE(apr_status_t) apr_queue_interrupt_all(apr_queue_t *queue)
365 Q_DBG("intr all", queue);
366 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
369 apr_thread_cond_broadcast(queue->not_empty);
370 apr_thread_cond_broadcast(queue->not_full);
372 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
379 APU_DECLARE(apr_status_t) apr_queue_term(apr_queue_t *queue)
383 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
391 queue->terminated = 1;
392 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
395 return apr_queue_interrupt_all(queue);