static int listener_may_exit = 0;
static int requests_this_child;
static int num_listensocks = 0;
+static apr_uint32_t connection_count = 0;
static int resource_shortage = 0;
static fd_queue_t *worker_queue;
static fd_queue_info_t *worker_queue_info;
}
/* unblock the listener if it's waiting for a worker */
- ap_queue_info_term(worker_queue_info);
+ ap_queue_info_term(worker_queue_info);
/*
* we should just be able to "kill(ap_my_pid, LISTENER_SIGNAL)" on all
static int volatile shutdown_pending;
static int volatile restart_pending;
ap_generation_t volatile ap_my_generation = 0;
-static apr_uint32_t connection_count = 0;
-static apr_status_t decrement_connection_count(void *dummy){
+static apr_status_t decrement_connection_count(void *dummy) {
apr_atomic_dec32(&connection_count);
return APR_SUCCESS;
}
}
static void close_listeners(int process_slot, int *closed) {
- if (!*closed){
+ if (!*closed) {
ap_listen_rec *lr;
int i;
for (lr = ap_listeners; lr != NULL; lr = lr->next) {
*closed = 1;
dying = 1;
ap_scoreboard_image->parent[process_slot].quiescing = 1;
- for (i = 0; i < threads_per_child; ++i){
+ for (i = 0; i < threads_per_child; ++i) {
ap_update_child_status_from_indexes(process_slot, i,
SERVER_DEAD, NULL);
}
}
}
-/* XXXXXX: Convert to skiplist or other better data structure
+/* XXXXXX: Convert to skiplist or other better data structure
* (yes, this is VERY VERY VERY VERY BAD)
*/
break;
}
}
-
+
if (!inserted) {
APR_RING_INSERT_TAIL(&timer_ring, te, timer_event_t, link);
}
conn_state_t *cs;
const apr_pollfd_t *out_pfd;
apr_int32_t num = 0;
- apr_time_t time_now = 0;
apr_interval_time_t timeout_interval;
- apr_time_t timeout_time;
+ apr_time_t timeout_time, now;
listener_poll_type *pt;
int closed = 0;
apr_signal(LISTENER_SIGNAL, dummy_signal_handler);
for (;;) {
- if (listener_may_exit){
+ if (listener_may_exit) {
close_listeners(process_slot, &closed);
if (terminate_mode == ST_UNGRACEFUL
|| apr_atomic_read32(&connection_count) == 0)
}
- {
- apr_time_t now = apr_time_now();
- apr_thread_mutex_lock(g_timer_ring_mtx);
-
- if (!APR_RING_EMPTY(&timer_ring, timer_event_t, link)) {
- te = APR_RING_FIRST(&timer_ring);
- if (te->when > now) {
- timeout_interval = te->when - now;
- }
- else {
- timeout_interval = 1;
- }
+ now = apr_time_now();
+ apr_thread_mutex_lock(g_timer_ring_mtx);
+ if (!APR_RING_EMPTY(&timer_ring, timer_event_t, link)) {
+ te = APR_RING_FIRST(&timer_ring);
+ if (te->when > now) {
+ timeout_interval = te->when - now;
}
else {
- timeout_interval = apr_time_from_msec(100);
+ timeout_interval = 1;
}
- apr_thread_mutex_unlock(g_timer_ring_mtx);
}
+ else {
+ timeout_interval = apr_time_from_msec(100);
+ }
+ apr_thread_mutex_unlock(g_timer_ring_mtx);
#if HAVE_SERF
rc = serf_context_prerun(g_serf);
if (rc != APR_SUCCESS) {
/* TOOD: what should do here? ugh. */
}
-
#endif
- rc = apr_pollset_poll(event_pollset, timeout_interval, &num,
- &out_pfd);
+ rc = apr_pollset_poll(event_pollset, timeout_interval, &num, &out_pfd);
if (rc != APR_SUCCESS) {
if (APR_STATUS_IS_EINTR(rc)) {
}
}
- if (listener_may_exit){
+ if (listener_may_exit) {
close_listeners(process_slot, &closed);
- if (terminate_mode == ST_UNGRACEFUL ||
- apr_atomic_read32(&connection_count) == 0) {
+ if (terminate_mode == ST_UNGRACEFUL
+ || apr_atomic_read32(&connection_count) == 0)
break;
- }
}
+ now = apr_time_now();
+ apr_thread_mutex_lock(g_timer_ring_mtx);
+ for (ep = APR_RING_FIRST(&timer_ring);
+ ep != APR_RING_SENTINEL(&timer_ring,
+ timer_event_t, link);
+ ep = APR_RING_FIRST(&timer_ring))
{
- apr_time_t now = apr_time_now();
- apr_thread_mutex_lock(g_timer_ring_mtx);
- for (ep = APR_RING_FIRST(&timer_ring);
- ep != APR_RING_SENTINEL(&timer_ring,
- timer_event_t, link);
- ep = APR_RING_FIRST(&timer_ring))
- {
- if (ep->when < now + EVENT_FUDGE_FACTOR) {
- APR_RING_REMOVE(ep, link);
- push_timer2worker(ep);
- }
- else {
- break;
- }
+ if (ep->when < now + EVENT_FUDGE_FACTOR) {
+ APR_RING_REMOVE(ep, link);
+ push_timer2worker(ep);
+ }
+ else {
+ break;
}
- apr_thread_mutex_unlock(g_timer_ring_mtx);
}
+ apr_thread_mutex_unlock(g_timer_ring_mtx);
while (num && get_worker(&have_idle_worker)) {
pt = (listener_poll_type *) out_pfd->client_data;
/* XXX possible optimization: stash the current time for use as
* r->request_time for new requests
*/
- time_now = apr_time_now();
+ now = apr_time_now();
/* handle timed out sockets */
apr_thread_mutex_lock(timeout_mutex);
/* Step 1: keepalive timeouts */
cs = APR_RING_FIRST(&keepalive_timeout_head);
- timeout_time = time_now + TIMEOUT_FUDGE_FACTOR;
+ timeout_time = now + TIMEOUT_FUDGE_FACTOR;
while (!APR_RING_EMPTY(&keepalive_timeout_head, conn_state_t, timeout_list)
&& cs->expiration_time < timeout_time) {
apr_status_t rv;
int is_idle = 0;
timer_event_t *te = NULL;
-
+
free(ti);
ap_scoreboard_image->servers[process_slot][thread_slot].pid = ap_my_pid;
}
te = NULL;
-
rv = ap_queue_pop_something(worker_queue, &csd, &cs, &ptrans, &te);
if (rv != APR_SUCCESS) {
continue;
}
if (te != NULL) {
-
te->cbfunc(te->baton);
{
}
ap_update_child_status_from_indexes(process_slot, thread_slot,
- (dying) ? SERVER_DEAD :
+ dying ? SERVER_DEAD :
SERVER_GRACEFUL,
(request_rec *) NULL);
apr_thread_mutex_create(&g_timer_ring_mtx, APR_THREAD_MUTEX_DEFAULT, pchild);
APR_RING_INIT(&timer_free_ring, timer_event_t, link);
APR_RING_INIT(&timer_ring, timer_event_t, link);
-
ap_run_child_init(pchild, ap_server_conf);
/* done with init critical section */
/* short cut if all active processes have been examined and
* enough empty scoreboard slots have been found
*/
-
+
break;
ps = &ap_scoreboard_image->parent[i];
for (j = 0; j < threads_per_child; j++) {