Lines Matching refs:queue
254 * it reaches into the queue and accesses "next" which can change.
296 #define ap_queue_full(queue) ((queue)->nelts == (queue)->bounds)
302 #define ap_queue_empty(queue) ((queue)->nelts == 0 && APR_RING_EMPTY(&queue->timers ,timer_event_t, link))
310 fd_queue_t *queue = data;
315 apr_thread_cond_destroy(queue->not_empty);
316 apr_thread_mutex_destroy(queue->one_big_mutex);
324 apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
330 if ((rv = apr_thread_mutex_create(&queue->one_big_mutex,
335 if ((rv = apr_thread_cond_create(&queue->not_empty, a)) != APR_SUCCESS) {
339 APR_RING_INIT(&queue->timers, timer_event_t, link);
341 queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t));
342 queue->bounds = queue_capacity;
343 queue->nelts = 0;
344 queue->in = 0;
345 queue->out = 0;
347 /* Set all the sockets in the queue to NULL */
349 queue->data[i].sd = NULL;
351 apr_pool_cleanup_register(a, queue, ap_queue_destroy,
358 * Push a new socket onto the queue.
363 apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
369 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
373 AP_DEBUG_ASSERT(!queue->terminated);
374 AP_DEBUG_ASSERT(!ap_queue_full(queue));
376 elem = &queue->data[queue->in];
377 queue->in++;
378 if (queue->in >= queue->bounds)
379 queue->in -= queue->bounds;
383 queue->nelts++;
385 apr_thread_cond_signal(queue->not_empty);
387 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
394 apr_status_t ap_queue_push_timer(fd_queue_t * queue, timer_event_t *te)
398 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
402 AP_DEBUG_ASSERT(!queue->terminated);
404 APR_RING_INSERT_TAIL(&queue->timers, te, timer_event_t, link);
406 apr_thread_cond_signal(queue->not_empty);
408 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
416 * Retrieves the next available socket from the queue. If there are no
421 apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd,
428 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
432 /* Keep waiting until we wake up and find that the queue is not empty. */
433 if (ap_queue_empty(queue)) {
434 if (!queue->terminated) {
435 apr_thread_cond_wait(queue->not_empty, queue->one_big_mutex);
438 if (ap_queue_empty(queue)) {
439 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
443 if (queue->terminated) {
454 if (!APR_RING_EMPTY(&queue->timers, timer_event_t, link)) {
455 *te_out = APR_RING_FIRST(&queue->timers);
459 elem = &queue->data[queue->out];
460 queue->out++;
461 if (queue->out >= queue->bounds)
462 queue->out -= queue->bounds;
463 queue->nelts--;
473 rv = apr_thread_mutex_unlock(queue->one_big_mutex);
477 apr_status_t ap_queue_interrupt_all(fd_queue_t * queue)
481 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
484 apr_thread_cond_broadcast(queue->not_empty);
485 return apr_thread_mutex_unlock(queue->one_big_mutex);
488 apr_status_t ap_queue_term(fd_queue_t * queue)
492 if ((rv = apr_thread_mutex_lock(queue->one_big_mutex)) != APR_SUCCESS) {
499 queue->terminated = 1;
500 if ((rv = apr_thread_mutex_unlock(queue->one_big_mutex)) != APR_SUCCESS) {
503 return ap_queue_interrupt_all(queue);