static int workers_may_exit = 0;
static int start_thread_may_exit = 0;
static int listener_may_exit = 0;
-static int requests_this_child;
static int num_listensocks = 0;
+/*
+ * As we don't have APR atomic functions for apr_int32_t, we use apr_uint32_t
+ * to actually store a signed value. This works as long as the platform uses
+ * two's complement representation. This assumption is also made in other
+ * parts of the code (e.g. fdqueue.c).
+ */
+static apr_uint32_t conns_this_child;
static apr_uint32_t connection_count = 0;
static int resource_shortage = 0;
static fd_queue_t *worker_queue;
static apr_status_t decrement_connection_count(void *dummy) {
apr_atomic_dec32(&connection_count);
+ apr_atomic_dec32(&conns_this_child);
return APR_SUCCESS;
}
/*
* process one connection in the worker
- * return: 1 if the connection has been completed,
- * 0 if it is still open and waiting for some event
*/
-static int process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock,
+static void process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock,
event_conn_state_t * cs, int my_child_num,
int my_thread_num)
{
apr_bucket_alloc_destroy(cs->bucket_alloc);
apr_pool_clear(p);
ap_push_pool(worker_queue_info, p);
- return 1;
+ apr_atomic_dec32(&conns_this_child);
+ return;
}
apr_atomic_inc32(&connection_count);
apr_pool_cleanup_register(c->pool, NULL, decrement_connection_count, apr_pool_cleanup_null);
cs->pfd.reqevents = APR_POLLOUT | APR_POLLHUP | APR_POLLERR;
rc = apr_pollset_add(event_pollset, &cs->pfd);
apr_thread_mutex_unlock(timeout_mutex);
- return 1;
+ return;
}
else if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted ||
listener_may_exit) {
if (cs->pub.state == CONN_STATE_LINGER) {
if (!start_lingering_close(cs))
- return 0;
+ return;
}
else if (cs->pub.state == CONN_STATE_CHECK_REQUEST_LINE_READABLE) {
apr_status_t rc;
AP_DEBUG_ASSERT(rc == APR_SUCCESS);
}
}
- return 1;
+ return;
}
-/* requests_this_child has gone to zero or below. See if the admin coded
+/* conns_this_child has gone to zero or below. See if the admin coded
"MaxConnectionsPerChild 0", and keep going in that case. Doing it this way
simplifies the hot path in worker_thread */
static void check_infinite_requests(void)
{
if (ap_max_requests_per_child) {
+ ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf,
+ "Stopping process due to MaxConnectionsPerChild");
signal_threads(ST_GRACEFUL);
}
else {
- requests_this_child = INT_MAX; /* keep going */
+ /* keep going */
+ apr_atomic_set32(&conns_this_child, APR_INT32_MAX);
}
}
break;
}
- if (requests_this_child <= 0) {
+ if (((apr_int32_t)apr_atomic_read32(&conns_this_child)) <= 0) {
check_infinite_requests();
}
else {
is_idle = 0;
worker_sockets[thread_slot] = csd;
- rv = process_socket(thd, ptrans, csd, cs, process_slot, thread_slot);
- if (!rv) {
- requests_this_child--;
- }
+ process_socket(thd, ptrans, csd, cs, process_slot, thread_slot);
worker_sockets[thread_slot] = NULL;
}
}
}
if (ap_max_requests_per_child) {
- requests_this_child = ap_max_requests_per_child;
+ apr_atomic_set32(&conns_this_child, (apr_uint32_t)ap_max_requests_per_child);
}
else {
/* coding a value of zero means infinity */
- requests_this_child = INT_MAX;
+ apr_atomic_set32(&conns_this_child, APR_INT32_MAX);
}
/* Setup worker threads */