Lines Matching refs:queue

191      * it reaches into the queue and accesses "next" which can change.
233 #define ap_queue_full(queue) ((queue)->nelts == (queue)->bounds)
239 #define ap_queue_empty(queue) ((queue)->nelts == 0)
247 fd_queue_t *queue = data;
252 apr_thread_cond_destroy(queue->not_empty);
253 apr_thread_mutex_destroy(queue->one_big_mutex);
261 apr_status_t ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a)
266 if ((rv = apr_thread_mutex_create(&queue->one_big_mutex,
270 if ((rv = apr_thread_cond_create(&queue->not_empty, a)) != APR_SUCCESS) {
274 queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
275 queue->bounds = queue_capacity;
276 queue->nelts = 0;
277 queue->in = 0;
278 queue->out = 0;
280 /* Set all the sockets in the queue to NULL */
282 queue->data[i].sd = NULL;
284 apr_pool_cleanup_register(a, queue, ap_queue_destroy, apr_pool_cleanup_null);
290 * Push a new socket onto the queue.
295 apr_status_t ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p)
300 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
304 AP_DEBUG_ASSERT(!queue->terminated);
305 AP_DEBUG_ASSERT(!ap_queue_full(queue));
307 elem = &queue->data[queue->in];
308 queue->in++;
309 if (queue->in >= queue->bounds)
310 queue->in -= queue->bounds;
313 queue->nelts++;
315 apr_thread_cond_signal(queue->not_empty);
317 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
325 * Retrieves the next available socket from the queue. If there are no
330 apr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p)
335 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
339 /* Keep waiting until we wake up and find that the queue is not empty. */
340 if (ap_queue_empty(queue)) {
341 if (!queue->terminated) {
342 apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
345 if (ap_queue_empty(queue)) {
346 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
350 if (queue->terminated) {
359 elem = &queue->data[queue->out];
360 queue->out++;
361 if (queue->out >= queue->bounds)
362 queue->out -= queue->bounds;
363 queue->nelts--;
371 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
375 apr_status_t ap_queue_interrupt_all(fd_queue_t *queue)
379 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
382 apr_thread_cond_broadcast(queue->not_empty);
383 return apr_thread_mutex_unlock(queue->one_big_mutex);
386 apr_status_t ap_queue_term(fd_queue_t *queue)
390 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
397 queue->terminated = 1;
398 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
401 return ap_queue_interrupt_all(queue);