[svn:mod_parrot] r502 - in mod_parrot/trunk: include src

[email protected] Mon, 24 Nov 2008 08:26:37 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Mon Nov 24 08:26:36 2008
New Revision: 502

Modified:
   mod_parrot/trunk/include/modparrot_config.h
   mod_parrot/trunk/src/mod_parrot.c

Log:
implement global connection cleanup handler


Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h	(original)
+++ mod_parrot/trunk/include/modparrot_config.h	Mon Nov 24 08:26:36 2008
@@ -110,6 +110,10 @@
 {
     apr_pool_t *pool;
     apr_array_header_t *ctx_pool;
+    int start_interp;
+    int minspare_interp;
+    int maxspare_interp;
+    int max_interp;
     char *init_path;
     int trace_flags;
     int enable_option_flags;

Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Mon Nov 24 08:26:36 2008
@@ -41,12 +41,6 @@
 
 #define NEXT_HANDLER_MODULE(x) (mpcfg->handler_modules[x] ? ((module **)mpcfg->module_array->elts)[((int *)mpcfg->handler_modules[x]->elts)[++(ctxp->module_index)]] : NULL);
 
-#ifdef MPM_IS_THREADED
-#define CONN_INDEX(c) (c->id % max_threads)
-#else
-#define CONN_INDEX(c) MP_CTX_ANY
-#endif
-
 /* declare our module */
 extern module AP_MODULE_DECLARE_DATA parrot_module;
 
@@ -64,6 +58,7 @@
 
 /* maps connection ID to a context so we can maintain state between phases */
 int *conn_ctx;
+#define CONN_CTX_INDEX(c) (c->id % max_threads)
 
 #ifdef MPM_IS_THREADED
 apr_thread_mutex_t *ctx_pool_mutex;
@@ -147,7 +142,7 @@
 
 #ifdef MPM_IS_THREADED
     if (c) {
-        conn_idx = c->id % max_threads;
+        conn_idx = CONN_CTX_INDEX(c);
         ctx_idx = conn_ctx[conn_idx];
     }
     else {
@@ -374,6 +369,22 @@
     return APR_SUCCESS;
 }
 
+static apr_status_t modparrot_conn_cleanup(void *data)
+{
+    conn_rec *c = (conn_rec *)data;
+
+    /* XXX when we stop releasing after every phase, we'll need to get the
+     * context and release it here.  until that happens, this is a no-op for
+     * non-threaded mpms. */
+
+#ifdef MPM_IS_THREADED
+    /* reset conn_ctx entry */
+    conn_ctx[CONN_CTX_INDEX(c)] = -1;
+#endif /* MPM_IS_THREADED */
+
+    return APR_SUCCESS;
+}
+
 #define MP_REQUEST_METAHANDLER(hname, henum, register_cleanup) \
     int modparrot_meta_##hname(request_rec *r) \
     { \
@@ -458,6 +469,10 @@
     mpcfg = ap_get_module_config(c->base_server->module_config, &parrot_module);
     if (!(mpcfg->option_flags & MP_OPT_ENABLE)) return DECLINED;
 
+    /* register cleanup handler to reset conn_ctx */
+    apr_pool_cleanup_register(c->pool, c, modparrot_conn_cleanup,
+        apr_pool_cleanup_null);
+
     /* get next module in line */
     modp = NEXT_HANDLER_MODULE(MP_HOOK_PRE_CONNECTION);