static void end_gen(mpm_gen_info_t *gi) { ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, ap_server_conf, "end of generation %d", gi->gen); ap_run_end_generation(ap_server_conf, gi->gen); APR_RING_REMOVE(gi, link); APR_RING_INSERT_HEAD(unused_geninfo, gi, mpm_gen_info_t, link); }
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; }
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; }
/* core's child-status hook * tracks number of remaining children per generation and * runs the end-generation hook when the last child of * a generation exits */ void ap_core_child_status(server_rec *s, pid_t pid, ap_generation_t gen, int slot, mpm_child_status status) { mpm_gen_info_t *cur; const char *status_msg = "unknown status"; if (!gen_head_init) { /* where to run this? */ gen_head_init = 1; geninfo = apr_pcalloc(s->process->pool, sizeof *geninfo); unused_geninfo = apr_pcalloc(s->process->pool, sizeof *unused_geninfo); APR_RING_INIT(geninfo, mpm_gen_info_t, link); APR_RING_INIT(unused_geninfo, mpm_gen_info_t, link); } cur = APR_RING_FIRST(geninfo); while (cur != APR_RING_SENTINEL(geninfo, mpm_gen_info_t, link) && cur->gen != gen) { cur = APR_RING_NEXT(cur, link); } switch(status) { case MPM_CHILD_STARTED: status_msg = "started"; if (cur == APR_RING_SENTINEL(geninfo, mpm_gen_info_t, link)) { /* first child for this generation */ if (!APR_RING_EMPTY(unused_geninfo, mpm_gen_info_t, link)) { cur = APR_RING_FIRST(unused_geninfo); APR_RING_REMOVE(cur, link); cur->active = cur->done = 0; } else { cur = apr_pcalloc(s->process->pool, sizeof *cur); } cur->gen = gen; APR_RING_ELEM_INIT(cur, link); APR_RING_INSERT_HEAD(geninfo, cur, mpm_gen_info_t, link); } ap_random_parent_after_fork(); ++cur->active; break; case MPM_CHILD_EXITED: ap_update_global_status(); status_msg = "exited"; if (cur == APR_RING_SENTINEL(geninfo, mpm_gen_info_t, link)) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(00546) "no record of generation %d of exiting child %" APR_PID_T_FMT, gen, pid); } else { --cur->active; if (!cur->active && cur->done) { /* no children, server has stopped/restarted */ end_gen(cur); } } break; case MPM_CHILD_LOST_SLOT: status_msg = "lost slot"; /* we don't track by slot, so it doesn't matter */ break; } ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, s, "mpm child %" APR_PID_T_FMT " (gen %d/slot %d) %s", pid, gen, slot, status_msg); }
/** * Add a resource to the beginning of the list, set the time at which * it was added to the list. * Assumes: that the reslist is locked. */ static void push_resource(apr_reslist_t *reslist, apr_res_t *resource) { APR_RING_INSERT_HEAD(&reslist->avail_list, resource, apr_res_t, link); resource->freed = apr_time_now(); reslist->nidle++; }