From a770ae9e77f6c2ecf6f366d207c00cabd63ead92 Mon Sep 17 00:00:00 2001 From: Cliff Woolley Date: Thu, 28 Aug 2003 05:54:44 +0000 Subject: [PATCH] Updated the various MPM's to use the new bucket_alloc_create_ex API when necessary. Which is to say that it's necessary in all cases except for prefork, where the change to apr-util to have it use the allocator from the pool passed in is already sufficient. Reviewed by: Jean-Jacques Clar, Sander Striker, Brad Nicholes git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101122 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 ++ server/mpm/beos/beos.c | 4 +-- server/mpm/experimental/leader/leader.c | 3 +- .../mpm/experimental/threadpool/threadpool.c | 6 ++-- server/mpm/mpmt_os2/mpmt_os2_child.c | 9 +++++- server/mpm/netware/mpm_netware.c | 29 +++++++++---------- server/mpm/worker/worker.c | 5 +--- 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CHANGES b/CHANGES index 6edcddbec2..75fb5ea719 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) The bucket brigades subsystem now honors the MaxMemFree setting. + [Cliff Woolley, Jean-Jacques Clar] + *) Fix mod_include's expression parser to recognize strings correctly even if they start with an escaped token. [André Malo] diff --git a/server/mpm/beos/beos.c b/server/mpm/beos/beos.c index 7e5c15e81f..2c68d69eaf 100644 --- a/server/mpm/beos/beos.c +++ b/server/mpm/beos/beos.c @@ -390,6 +390,8 @@ static int32 worker_thread(void * dummy) apr_pool_tag(ptrans, "transaction"); + bucket_alloc = apr_bucket_alloc_create_ex(allocator); + apr_thread_mutex_lock(worker_thread_count_mutex); worker_thread_count++; apr_thread_mutex_unlock(worker_thread_count_mutex); @@ -400,8 +402,6 @@ static int32 worker_thread(void * dummy) apr_poll_setup(&pollset, num_listening_sockets + 1, tpool); for(n=0 ; n <= num_listening_sockets ; n++) apr_poll_socket_add(pollset, listening_sockets[n], APR_POLLIN); - - bucket_alloc = apr_bucket_alloc_create(tpool); while (1) { /* If we're here, then chances are (unless we're the first thread created) diff --git a/server/mpm/experimental/leader/leader.c b/server/mpm/experimental/leader/leader.c index e427789ab1..f66ae10971 100644 --- a/server/mpm/experimental/leader/leader.c +++ b/server/mpm/experimental/leader/leader.c @@ -715,9 +715,10 @@ static void *worker_thread(apr_thread_t *thd, void * dummy) apr_allocator_create(&allocator); apr_allocator_max_free_set(allocator, ap_max_mem_free); + /* XXX: why is ptrans's parent not tpool? --jcw 08/2003 */ apr_pool_create_ex(&ptrans, NULL, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); - bucket_alloc = apr_bucket_alloc_create(tpool); + bucket_alloc = apr_bucket_alloc_create_ex(allocator); apr_poll_setup(&pollset, num_listensocks, tpool); for(lr = ap_listeners ; lr != NULL ; lr = lr->next) diff --git a/server/mpm/experimental/threadpool/threadpool.c b/server/mpm/experimental/threadpool/threadpool.c index ca69c00eb2..f4558de44f 100644 --- a/server/mpm/experimental/threadpool/threadpool.c +++ b/server/mpm/experimental/threadpool/threadpool.c @@ -981,12 +981,10 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy) apr_allocator_create(&allocator); apr_allocator_max_free_set(allocator, ap_max_mem_free); + /* XXX: why is ptrans's parent not tpool? --jcw 08/2003 */ apr_pool_create_ex(&ptrans, NULL, NULL, allocator); apr_allocator_owner_set(allocator, ptrans); - - /* XXX: What happens if this is allocated from the - * single-thread-optimized ptrans pool? -aaron */ - bucket_alloc = apr_bucket_alloc_create(tpool); + bucket_alloc = apr_bucket_alloc_create_ex(allocator); wakeup = (worker_wakeup_info *)apr_palloc(tpool, sizeof(*wakeup)); wakeup->pool = ptrans; diff --git a/server/mpm/mpmt_os2/mpmt_os2_child.c b/server/mpm/mpmt_os2/mpmt_os2_child.c index fe7fba207a..af55e6de28 100644 --- a/server/mpm/mpmt_os2/mpmt_os2_child.c +++ b/server/mpm/mpmt_os2/mpmt_os2_child.c @@ -402,6 +402,7 @@ static void worker_main(void *vpArg) long conn_id; conn_rec *current_conn; apr_pool_t *pconn; + apr_allocator_t *allocator; apr_bucket_alloc_t *bucket_alloc; worker_args_t *worker_args; HQUEUE workq; @@ -430,10 +431,13 @@ static void worker_main(void *vpArg) ap_update_child_status_from_indexes(child_slot, thread_slot, SERVER_READY, NULL); + apr_allocator_create(&allocator); + apr_allocator_max_free_set(allocator, ap_max_mem_free); + bucket_alloc = apr_bucket_alloc_create_ex(allocator); + while (rc = DosReadQueue(workq, &rd, &len, (PPVOID)&worker_args, 0, DCWW_WAIT, &priority, NULLHANDLE), rc == 0 && rd.ulData != WORKTYPE_EXIT) { pconn = worker_args->pconn; - bucket_alloc = apr_bucket_alloc_create(pconn); ap_create_sb_handle(&sbh, pconn, child_slot, thread_slot); current_conn = ap_run_create_connection(pconn, ap_server_conf, worker_args->conn_sd, conn_id, @@ -451,6 +455,9 @@ static void worker_main(void *vpArg) ap_update_child_status_from_indexes(child_slot, thread_slot, SERVER_DEAD, NULL); + + apr_bucket_alloc_destroy(bucket_alloc); + apr_allocator_destroy(allocator); } diff --git a/server/mpm/netware/mpm_netware.c b/server/mpm/netware/mpm_netware.c index b252cf4b71..4c206ab42f 100644 --- a/server/mpm/netware/mpm_netware.c +++ b/server/mpm/netware/mpm_netware.c @@ -212,14 +212,14 @@ static int volatile wait_to_finish=1; ap_generation_t volatile ap_my_generation=0; /* a clean exit from a child with proper cleanup */ -static void clean_child_exit(int code, int worker_num, apr_pool_t *pthrd, +static void clean_child_exit(int code, int worker_num, apr_pool_t *ptrans, apr_bucket_alloc_t *bucket_alloc) __attribute__ ((noreturn)); -static void clean_child_exit(int code, int worker_num, apr_pool_t *pthrd, +static void clean_child_exit(int code, int worker_num, apr_pool_t *ptrans, apr_bucket_alloc_t *bucket_alloc) { + apr_bucket_alloc_destroy(bucket_alloc); if (!shutdown_pending) { - apr_bucket_alloc_destroy(bucket_alloc); - apr_pool_destroy(pthrd); + apr_pool_destroy(ptrans); } atomic_dec (&worker_thread_count); @@ -359,7 +359,7 @@ static int avg_retries = 0; void worker_main(void *arg) { ap_listen_rec *lr, *first_lr, *last_lr = NULL; - apr_pool_t *ptrans, *pthrd; + apr_pool_t *ptrans; apr_pool_t *pbucket; apr_allocator_t *allocator; apr_bucket_alloc_t *bucket_alloc; @@ -384,14 +384,11 @@ void worker_main(void *arg) apr_allocator_create(&allocator); apr_allocator_max_free_set(allocator, ap_max_mem_free); - apr_pool_create_ex(&pthrd, pmain, NULL, allocator); - apr_allocator_owner_set(allocator, pthrd); - apr_pool_tag(pthrd, "worker_thrd_pool"); - - apr_pool_create(&ptrans, pthrd); + apr_pool_create_ex(&ptrans, pmain, NULL, allocator); + apr_allocator_owner_set(allocator, ptrans); apr_pool_tag(ptrans, "transaction"); - bucket_alloc = apr_bucket_alloc_create(pthrd); + bucket_alloc = apr_bucket_alloc_create_ex(allocator); atomic_inc (&worker_thread_count); @@ -405,7 +402,7 @@ void worker_main(void *arg) if ((ap_max_requests_per_child > 0 && requests_this_child++ >= ap_max_requests_per_child)) { DBPRINT1 ("\n**Thread slot %d is shutting down", my_worker_num); - clean_child_exit(0, my_worker_num, pthrd, bucket_alloc); + clean_child_exit(0, my_worker_num, ptrans, bucket_alloc); } ap_update_child_status_from_indexes(0, my_worker_num, WORKER_READY, @@ -418,7 +415,7 @@ void worker_main(void *arg) for (;;) { if (shutdown_pending || restart_pending || (ap_scoreboard_image->servers[0][my_worker_num].status == WORKER_IDLE_KILL)) { DBPRINT1 ("\nThread slot %d is shutting down\n", my_worker_num); - clean_child_exit(0, my_worker_num, pthrd, bucket_alloc); + clean_child_exit(0, my_worker_num, ptrans, bucket_alloc); } /* Check the listen queue on all sockets for requests */ @@ -527,13 +524,13 @@ void worker_main(void *arg) */ ap_log_error(APLOG_MARK, APLOG_EMERG, stat, ap_server_conf, "apr_accept: giving up."); - clean_child_exit(APEXIT_CHILDFATAL, my_worker_num, pthrd, + clean_child_exit(APEXIT_CHILDFATAL, my_worker_num, ptrans, bucket_alloc); } else { ap_log_error(APLOG_MARK, APLOG_ERR, stat, ap_server_conf, "apr_accept: (client socket)"); - clean_child_exit(1, my_worker_num, pthrd, bucket_alloc); + clean_child_exit(1, my_worker_num, ptrans, bucket_alloc); } } } @@ -552,7 +549,7 @@ void worker_main(void *arg) } request_count++; } - clean_child_exit(0, my_worker_num, pthrd, bucket_alloc); + clean_child_exit(0, my_worker_num, ptrans, bucket_alloc); } diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 6025bd99a0..563c3bcafb 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -825,8 +825,6 @@ static void * APR_THREAD_FUNC worker_thread(apr_thread_t *thd, void * dummy) ap_update_child_status_from_indexes(process_slot, thread_slot, SERVER_STARTING, NULL); - bucket_alloc = apr_bucket_alloc_create(apr_thread_pool_get(thd)); - while (!workers_may_exit) { if (!is_idle) { rv = ap_queue_info_set_idle(worker_queue_info, last_ptrans); @@ -878,6 +876,7 @@ worker_pop: } is_idle = 0; worker_sockets[thread_slot] = csd; + bucket_alloc = apr_bucket_alloc_create(ptrans); process_socket(ptrans, csd, process_slot, thread_slot, bucket_alloc); worker_sockets[thread_slot] = NULL; requests_this_child--; /* FIXME: should be synchronized - aaron */ @@ -888,8 +887,6 @@ worker_pop: ap_update_child_status_from_indexes(process_slot, thread_slot, (dying) ? SERVER_DEAD : SERVER_GRACEFUL, (request_rec *) NULL); - apr_bucket_alloc_destroy(bucket_alloc); - apr_thread_exit(thd, APR_SUCCESS); return NULL; } -- 2.50.1