This patch converts the AP_CHILD_THREAD_FROM_ID macro into two macros: AP_CHILD_PSLOT_FROM_ID and AP_CHILD_TSLOT_FROM_ID. This was done so that the values returned could be cached and reused, instead of calling the macro over and over (which in many cases hides a multiplcation and division of a long int).
I've changed the macro on all MPMs, and in all places in the core code where the original macro was being used. Please review and commit. -aaron p.s. this is a half-step toward the plan to replace conn_rec->id with two ints for the slots. Since conn_rec->id is used so often throughout the code, I decided to hold off on that more radical change until after this is in place. Index: server/connection.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/connection.c,v retrieving revision 1.84 diff -u -r1.84 connection.c --- server/connection.c 2001/07/31 00:34:27 1.84 +++ server/connection.c 2001/10/01 22:03:21 @@ -157,7 +157,9 @@ apr_int32_t timeout; apr_int32_t total_linger_time = 0; - ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_CLOSING, NULL); + ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(c->id), + AP_CHILD_TSLOT_FROM_ID(c->id), + SERVER_CLOSING, NULL); #ifdef NO_LINGCLOSE ap_flush_conn(c); /* just close it */ @@ -230,7 +232,8 @@ conn_rec *conn = (conn_rec *) apr_pcalloc(p, sizeof(conn_rec)); apr_status_t rv; - (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(id), + (void) ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(id), + AP_CHILD_TSLOT_FROM_ID(id), SERVER_BUSY_READ, (request_rec *) NULL); /* Got a connection structure, so initialize what fields we can Index: server/protocol.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/protocol.c,v retrieving revision 1.47 diff -u -r1.47 protocol.c --- server/protocol.c 2001/09/29 08:48:59 1.47 +++ server/protocol.c 2001/10/01 22:03:22 @@ -413,7 +413,9 @@ /* XXX If we want to keep track of the Method, the protocol module should do * it. That support isn't in the scoreboard yet. Hopefully next week * sometime. rbb */ - ap_update_connection_status(AP_CHILD_THREAD_FROM_ID(conn->id), "Method", r->method); + ap_update_connection_status(AP_CHILD_PSLOT_FROM_ID(conn->id), + AP_CHILD_TSLOT_FROM_ID(conn->id), + "Method", r->method); #endif uri = ap_getword_white(r->pool, &ll); Index: server/mpm/beos/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/beos/mpm_default.h,v retrieving revision 1.4 diff -u -r1.4 mpm_default.h --- server/mpm/beos/mpm_default.h 2001/02/16 04:26:50 1.4 +++ server/mpm/beos/mpm_default.h 2001/10/01 22:03:22 @@ -62,7 +62,8 @@ /* we use the child (c) as zero in our code... */ #define AP_ID_FROM_CHILD_THREAD(c, t) t /* as the child is always zero, just return the id... */ -#define AP_CHILD_THREAD_FROM_ID(i) 0 , i +#define AP_CHILD_PSLOT_FROM_ID(i) 0 +#define AP_CHILD_TSLOT_FROM_ID(i) i /* Number of threads to spawn off by default --- also, if fewer than * this free when the caretaker checks, it will spawn more. Index: server/mpm/mpmt_os2/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/mpmt_os2/mpm_default.h,v retrieving revision 1.1 diff -u -r1.1 mpm_default.h --- server/mpm/mpmt_os2/mpm_default.h 2001/08/17 17:07:34 1.1 +++ server/mpm/mpmt_os2/mpm_default.h 2001/10/01 22:03:23 @@ -109,8 +109,11 @@ #define DEFAULT_MAX_REQUESTS_PER_CHILD 10000 #endif -/* AP_CHILD_THREAD_FROM_ID is used by the scoreboard. */ -#define AP_CHILD_THREAD_FROM_ID(i) (i / HARD_THREAD_LIMIT), (i % HARD_THREAD_LIMIT) +/* AP_CHILD_PSLOT_FROM_ID and AP_CHILD_TSLOT_FROM_ID are + * used by the scoreboard. + */ +#define AP_CHILD_PSLOT_FROM_ID(i) (i / HARD_THREAD_LIMIT) +#define AP_CHILD_TSLOT_FROM_ID(i) (i % HARD_THREAD_LIMIT) #define AP_ID_FROM_CHILD_THREAD(c, t) ((c * HARD_THREAD_LIMIT) + t) #endif /* AP_MPM_DEFAULT_H */ Index: server/mpm/perchild/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/perchild/mpm_default.h,v retrieving revision 1.7 diff -u -r1.7 mpm_default.h --- server/mpm/perchild/mpm_default.h 2001/02/16 04:26:50 1.7 +++ server/mpm/perchild/mpm_default.h 2001/10/01 22:03:23 @@ -60,7 +60,8 @@ #define APACHE_MPM_DEFAULT_H #define AP_ID_FROM_CHILD_THREAD(c, t) ((c * HARD_THREAD_LIMIT) + t) -#define AP_CHILD_THREAD_FROM_ID(i) (i / HARD_THREAD_LIMIT), (i % HARD_THREAD_LIMIT) +#define AP_CHILD_PSLOT_FROM_ID(i) (i / HARD_THREAD_LIMIT) +#define AP_CHILD_TSLOT_FROM_ID(i) (i % HARD_THREAD_LIMIT) /* Number of threads to spawn off by default --- also, if fewer than * this free when the caretaker checks, it will spawn more. Index: server/mpm/prefork/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/prefork/mpm_default.h,v retrieving revision 1.6 diff -u -r1.6 mpm_default.h --- server/mpm/prefork/mpm_default.h 2001/02/16 04:26:51 1.6 +++ server/mpm/prefork/mpm_default.h 2001/10/01 22:03:23 @@ -60,7 +60,8 @@ #define APACHE_MPM_DEFAULT_H #define AP_ID_FROM_CHILD_THREAD(c, t) c -#define AP_CHILD_THREAD_FROM_ID(i) i, 0 +#define AP_CHILD_PSLOT_FROM_ID(i) i +#define AP_CHILD_TSLOT_FROM_ID(i) 0 /* Number of servers to spawn off by default --- also, if fewer than Index: server/mpm/prefork/prefork.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/prefork/prefork.c,v retrieving revision 1.201 diff -u -r1.201 prefork.c --- server/mpm/prefork/prefork.c 2001/09/18 22:13:58 1.201 +++ server/mpm/prefork/prefork.c 2001/10/01 22:03:24 @@ -377,7 +377,9 @@ ap_sync_scoreboard_image(); if (ap_scoreboard_image->servers[n][0].status != SERVER_DEAD && kill((pid = ap_scoreboard_image->parent[n].pid), 0) == -1) { - ap_update_child_status(AP_CHILD_THREAD_FROM_ID(n), SERVER_DEAD, NULL); + ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(n), + AP_CHILD_TSLOT_FROM_ID(n), + SERVER_DEAD, NULL); /* just mark it as having a successful exit status */ memset(status, 0, sizeof(apr_wait_t)); return(pid); @@ -605,7 +607,9 @@ ap_run_child_init(pchild, ap_server_conf); - (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(my_child_num), SERVER_READY, (request_rec *) NULL); + (void) ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(my_child_num), + AP_CHILD_TSLOT_FROM_ID(my_child_num), + SERVER_READY, (request_rec *)NULL); ap_sync_scoreboard_image(); while (!die_now) { @@ -622,7 +626,9 @@ clean_child_exit(0); } - (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(my_child_num), SERVER_READY, (request_rec *) NULL); + (void) ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(my_child_num), + AP_CHILD_TSLOT_FROM_ID(my_child_num), + SERVER_READY, (request_rec *)NULL); /* * Wait for an acceptable connection to arrive. @@ -866,7 +872,9 @@ child_main(slot); } - (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(slot), SERVER_STARTING, (request_rec *) NULL); + (void) ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(slot), + AP_CHILD_TSLOT_FROM_ID(slot), + SERVER_STARTING, (request_rec *)NULL); #ifdef _OSD_POSIX @@ -882,7 +890,9 @@ /* fork didn't succeed. Fix the scoreboard or else * it will say SERVER_STARTING forever and ever */ - (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(slot), SERVER_DEAD, (request_rec *) NULL); + (void) ap_update_child_status(AP_CHILD_PSLOT_FROM_ID(slot), + AP_CHILD_TSLOT_FROM_ID(slot), + SERVER_DEAD, (request_rec *) NULL); /* In case system resources are maxxed out, we don't want Apache running away with the CPU trying to fork over and @@ -1187,8 +1197,10 @@ ap_sync_scoreboard_image(); child_slot = find_child_by_pid(&pid); if (child_slot >= 0) { - (void) ap_update_child_status(AP_CHILD_THREAD_FROM_ID(child_slot), SERVER_DEAD, - (request_rec *) NULL); + (void) ap_update_child_status( + AP_CHILD_PSLOT_FROM_ID(child_slot), + AP_CHILD_TSLOT_FROM_ID(child_slot), + SERVER_DEAD, (request_rec *)NULL); if (remaining_children_to_start && child_slot < ap_daemons_limit) { /* we're still doing a 1-for-1 replacement of dead Index: server/mpm/spmt_os2/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/spmt_os2/mpm_default.h,v retrieving revision 1.6 diff -u -r1.6 mpm_default.h --- server/mpm/spmt_os2/mpm_default.h 2001/02/16 04:26:51 1.6 +++ server/mpm/spmt_os2/mpm_default.h 2001/10/01 22:03:24 @@ -117,7 +117,11 @@ #define DEFAULT_MAX_REQUESTS_PER_CHILD 10000 #endif -/* AP_CHILD_THREAD_FROM_ID is used by the scoreboard. */ -#define AP_CHILD_THREAD_FROM_ID(i) 0, i +/* AP_CHILD_PSLOT_FROM_ID and AP_CHILD_TSLOT_FROM_ID are + * used by the scoreboard. In our single-process model + * our single-child always uses slot 0. + */ +#define AP_CHILD_PSLOT_FROM_ID(i) 0 +#define AP_CHILD_TSLOT_FROM_ID(i) i #endif /* AP_MPM_DEFAULT_H */ Index: server/mpm/threaded/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/threaded/mpm_default.h,v retrieving revision 1.2 diff -u -r1.2 mpm_default.h --- server/mpm/threaded/mpm_default.h 2001/02/22 18:54:45 1.2 +++ server/mpm/threaded/mpm_default.h 2001/10/01 22:03:24 @@ -60,7 +60,8 @@ #define APACHE_MPM_DEFAULT_H #define AP_ID_FROM_CHILD_THREAD(c, t) ((c * HARD_THREAD_LIMIT) + t) -#define AP_CHILD_THREAD_FROM_ID(i) (i / HARD_THREAD_LIMIT), (i % HARD_THREAD_LIMIT) +#define AP_CHILD_PSLOT_FROM_ID(i) (i / HARD_THREAD_LIMIT) +#define AP_CHILD_TSLOT_FROM_ID(i) (i % HARD_THREAD_LIMIT) /* Number of servers to spawn off by default --- also, if fewer than * this free when the caretaker checks, it will spawn more. Index: server/mpm/winnt/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/winnt/mpm_default.h,v retrieving revision 1.9 diff -u -r1.9 mpm_default.h --- server/mpm/winnt/mpm_default.h 2001/02/16 04:26:52 1.9 +++ server/mpm/winnt/mpm_default.h 2001/10/01 22:03:25 @@ -59,8 +59,12 @@ #ifndef APACHE_MPM_DEFAULT_H #define APACHE_MPM_DEFAULT_H -/* AP_CHILD_THREAD_FROM_ID is used by the scoreboard. */ -#define AP_CHILD_THREAD_FROM_ID(i) 0, i +/* AP_CHILD_PSLOT_FROM_ID and AP_CHILD_TSLOT_FROM_ID are + * used by the scoreboard. In our single-process model + * our single-child always uses slot 0. + */ +#define AP_CHILD_PSLOT_FROM_ID(i) 0 +#define AP_CHILD_TSLOT_FROM_ID(i) i /* Number of threads to spawn off by default --- also, if fewer than * this free when the caretaker checks, it will spawn more. Index: server/mpm/worker/mpm_default.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/mpm/worker/mpm_default.h,v retrieving revision 1.2 diff -u -r1.2 mpm_default.h --- server/mpm/worker/mpm_default.h 2001/09/24 23:03:42 1.2 +++ server/mpm/worker/mpm_default.h 2001/10/01 22:03:25 @@ -60,7 +60,8 @@ #define APACHE_MPM_DEFAULT_H #define AP_ID_FROM_CHILD_THREAD(c, t) ((c * HARD_THREAD_LIMIT) + t) -#define AP_CHILD_THREAD_FROM_ID(i) (i / HARD_THREAD_LIMIT), (i % HARD_THREAD_LIMIT) +#define AP_CHILD_PSLOT_FROM_ID(i) (i / HARD_THREAD_LIMIT) +#define AP_CHILD_TSLOT_FROM_ID(i) (i % HARD_THREAD_LIMIT) /* Number of servers to spawn off by default --- also, if fewer than * this free when the caretaker checks, it will spawn more. Index: modules/http/http_core.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/modules/http/http_core.c,v retrieving revision 1.285 diff -u -r1.285 http_core.c --- modules/http/http_core.c 2001/09/30 04:17:16 1.285 +++ modules/http/http_core.c 2001/10/01 22:03:25 @@ -273,28 +273,30 @@ static int ap_process_http_connection(conn_rec *c) { request_rec *r; + int pslot = AP_CHILD_PSLOT_FROM_ID(c->id); + int tslot = AP_CHILD_TSLOT_FROM_ID(c->id); /* * Read and process each request found on our connection * until no requests are left or we decide to close. */ - ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_BUSY_READ, NULL); + ap_update_child_status(pslot, tslot, SERVER_BUSY_READ, NULL); while ((r = ap_read_request(c)) != NULL) { /* process the request if it was read without error */ - ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_BUSY_WRITE, r); + ap_update_child_status(pslot, tslot, SERVER_BUSY_WRITE, r); if (r->status == HTTP_OK) ap_process_request(r); if (ap_extended_status) - ap_increment_counts(AP_CHILD_THREAD_FROM_ID(c->id), r); + ap_increment_counts(pslot, tslot, r); if (!c->keepalive || c->aborted) break; - ap_update_child_status(AP_CHILD_THREAD_FROM_ID(c->id), SERVER_BUSY_KEEPALIVE, r); + ap_update_child_status(pslot, tslot, SERVER_BUSY_KEEPALIVE, r); apr_pool_destroy(r->pool); if (ap_graceful_stop_signalled())