Example #1
0
static apr_status_t mmap_cleanup(void *themmap)
{
    apr_mmap_t *mm = themmap;
    apr_mmap_t *next = APR_RING_NEXT(mm,link);
    int rv = 0;

    /* we no longer refer to the mmaped region */
    APR_RING_REMOVE(mm,link);
    APR_RING_NEXT(mm,link) = NULL;
    APR_RING_PREV(mm,link) = NULL;

    if (next != mm) {
        /* more references exist, so we're done */
        return APR_SUCCESS;
    }

#ifdef BEOS
    rv = delete_area(mm->area);
#else
    rv = munmap(mm->mm, mm->size);
#endif
    mm->mm = (void *)-1;

    if (rv == 0) {
        return APR_SUCCESS;
    }
    return errno;
}
Example #2
0
APT_DECLARE(apt_list_elem_t*) apt_list_prev_elem_get(apt_obj_list_t *list, apt_list_elem_t *elem)
{
	apt_list_elem_t *prev_elem = APR_RING_PREV(elem,link);
	if(prev_elem == APR_RING_SENTINEL(&list->head,apt_list_elem_t,link)) {
		prev_elem = NULL;
	}
	return prev_elem;
}
Example #3
0
static void mpf_timers_reschedule(mpf_timer_manager_t *manager)
{
    mpf_timer_t *it;
    for(it = APR_RING_LAST(&manager->head);
            it != APR_RING_SENTINEL(&manager->head, mpf_timer_t, link);
            it = APR_RING_PREV(it, link)) {

        it->scheduled_time -= manager->elapsed_time;
    }
    manager->elapsed_time = 0;
}
Example #4
0
static void apt_timers_reschedule(apt_timer_queue_t *queue)
{
    apt_timer_t *it;
    for(it = APR_RING_LAST(&queue->head);
            it != APR_RING_SENTINEL(&queue->head, apt_timer_t, link);
            it = APR_RING_PREV(it, link)) {

        it->scheduled_time -= queue->elapsed_time;
    }
    queue->elapsed_time = 0;
}
/*
 * This function stop extra idle threads to the cnt.
 * @return the number of threads stopped
 * NOTE: There could be busy threads become idle during this function
 */
static struct apr_thread_list_elt *trim_threads(apr_thread_pool_t *me,
                                                apr_size_t *cnt, int idle)
{
    struct apr_thread_list *thds;
    apr_size_t n, n_dbg, i;
    struct apr_thread_list_elt *head, *tail, *elt;

    apr_thread_mutex_lock(me->lock);
    if (idle) {
        thds = me->idle_thds;
        n = me->idle_cnt;
    }
    else {
        thds = me->busy_thds;
        n = me->thd_cnt - me->idle_cnt;
    }
    if (n <= *cnt) {
        apr_thread_mutex_unlock(me->lock);
        *cnt = 0;
        return NULL;
    }
    n -= *cnt;

    head = APR_RING_FIRST(thds);
    for (i = 0; i < *cnt; i++) {
        head = APR_RING_NEXT(head, link);
    }
    tail = APR_RING_LAST(thds);
    if (idle) {
        APR_RING_UNSPLICE(head, tail, link);
        me->idle_cnt = *cnt;
    }

    n_dbg = 0;
    for (elt = head; elt != tail; elt = APR_RING_NEXT(elt, link)) {
        elt->state = TH_STOP;
        n_dbg++;
    }
    elt->state = TH_STOP;
    n_dbg++;
    assert(n == n_dbg);
    *cnt = n;

    apr_thread_mutex_unlock(me->lock);

    APR_RING_PREV(head, link) = NULL;
    APR_RING_NEXT(tail, link) = NULL;
    return head;
}
Example #6
0
static APR_INLINE apt_bool_t mpf_timer_insert(mpf_timer_manager_t *manager, mpf_timer_t *timer)
{
    mpf_timer_t *it;
    for(it = APR_RING_LAST(&manager->head);
            it != APR_RING_SENTINEL(&manager->head, mpf_timer_t, link);
            it = APR_RING_PREV(it, link)) {

        if(it->scheduled_time <= timer->scheduled_time) {
            APR_RING_INSERT_AFTER(it,timer,link);
            return TRUE;
        }
    }
    APR_RING_INSERT_HEAD(&manager->head,timer,mpf_timer_t,link);
    return TRUE;
}
Example #7
0
static APR_INLINE apt_bool_t apt_timer_insert(apt_timer_queue_t *timer_queue, apt_timer_t *timer)
{
    apt_timer_t *it;
    for(it = APR_RING_LAST(&timer_queue->head);
            it != APR_RING_SENTINEL(&timer_queue->head, apt_timer_t, link);
            it = APR_RING_PREV(it, link)) {

        if(it->scheduled_time <= timer->scheduled_time) {
            APR_RING_INSERT_AFTER(it,timer,link);
            return TRUE;
        }
    }
    APR_RING_INSERT_HEAD(&timer_queue->head,timer,apt_timer_t,link);
    return TRUE;
}
Example #8
0
static apr_status_t mmap_cleanup(void *themmap)
{
    apr_mmap_t *mm = themmap;
    apr_mmap_t *next = APR_RING_NEXT(mm,link);
    apr_status_t rv = 0;

    /* we no longer refer to the mmaped region */
    APR_RING_REMOVE(mm,link);
    APR_RING_NEXT(mm,link) = NULL;
    APR_RING_PREV(mm,link) = NULL;

    if (next != mm) {
        /* more references exist, so we're done */
        return APR_SUCCESS;
    }

    if (mm->mv) {
        if (!UnmapViewOfFile(mm->mv))
        {
            apr_status_t rv = apr_get_os_error();
            CloseHandle(mm->mhandle);
            mm->mv = NULL;
            mm->mhandle = NULL;
            return rv;
        }
        mm->mv = NULL;
    }
    if (mm->mhandle) 
    {
        if (!CloseHandle(mm->mhandle))
        {
            apr_status_t rv = apr_get_os_error();
            CloseHandle(mm->mhandle);
            mm->mhandle = NULL;
            return rv;
        }
        mm->mhandle = NULL;
    }
    return APR_SUCCESS;
}