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

[email protected]
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Mon Dec 17 10:10:58 2007
New Revision: 278

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

Log:
destroy interpreters on server stop/restart


Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h	(original)
+++ mod_parrot/trunk/include/mod_parrot.h	Mon Dec 17 10:10:58 2007
@@ -62,6 +62,7 @@
 int modparrot_hll_handler(Parrot_Interp, char *, char *, char *, int *);
 Parrot_PMC get_sub_pmc(Parrot_Interp , char *, char *);
 int mp_ctx_pool_init(apr_pool_t *, int);
+void mp_ctx_pool_destroy(void);
 modparrot_context *reserve_ctx(void);
 void release_ctx(modparrot_context *);
 modparrot_context *get_interp_ctx(Parrot_Interp);

Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c	(original)
+++ mod_parrot/trunk/src/context.c	Mon Dec 17 10:10:58 2007
@@ -55,6 +55,22 @@
     return 1;
 }
 
+/* destroy pool of contexts */
+void mp_ctx_pool_destroy(void)
+{
+    modparrot_context *ctx;
+
+    if (!mp_ctx_pool) return;
+
+    /* pop each context off the list and destroy its interpreter */
+    while (ctx = apr_array_pop(mp_ctx_pool)) {
+        if (ctx->interp) modparrot_destroy_interpreter(ctx->interp);
+    }
+
+    /* set the pool to null and let apache deal with the leftover garbage */
+    mp_ctx_pool = (apr_array_header_t *)NULL;
+}
+
 /* finds and reserves a context for use by a handler */
 modparrot_context *reserve_ctx(void)
 {

Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Mon Dec 17 10:10:58 2007
@@ -825,6 +825,14 @@
     return handler_status;
 }
 
+static apr_status_t modparrot_cleanup(void *data)
+{
+    server_rec *s = (server_rec *)data;
+
+    mp_ctx_pool_destroy();
+    return APR_SUCCESS;
+}
+
 static int modparrot_open_logs_handler(apr_pool_t *pconf, apr_pool_t *plog,
     apr_pool_t *ptemp, server_rec *s)
 {
@@ -839,6 +847,10 @@
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
+    /* destroy context pool on cleanup */
+    apr_pool_cleanup_register(pconf, s, modparrot_cleanup,
+        apr_pool_cleanup_null);
+
     /* get apache configs */
     cfg = ap_get_module_config(s->module_config, &parrot_module);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.