[svn:mod_parrot] r520 - in mod_parrot/trunk: include src
[email protected] Fri, 5 Dec 2008 10:10:08 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Fri Dec 5 10:10:07 2008
New Revision: 520
Modified:
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/modparrot_config.c
mod_parrot/trunk/src/module.c
Log:
merge changes from userdata branch
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Fri Dec 5 10:10:07 2008
@@ -39,6 +39,9 @@
#define MODPARROT_CTX_UNLOCK(x) (x->locked = 0)
#define MP_CTX_ANY (-1)
+/* keys */
+#define MP_KEY_CTX "modparrot-context"
+
/* we need to move things around to avoid this */
#include "modparrot_config.h"
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Fri Dec 5 10:10:07 2008
@@ -56,10 +56,6 @@
/* thread info */
int hard_thread_limit, max_threads;
-/* 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)
-
struct modparrot_cleanup_info {
int module_index; /* the HLL module that registered us */
Parrot_PMC callback; /* callback subroutine */
@@ -138,55 +134,60 @@
return(interp);
}
-static modparrot_context *init_ctx(server_rec *s, conn_rec *c)
+static modparrot_context *modparrot_get_current_ctx(apr_pool_t *p)
{
- Parrot_Interp interp;
modparrot_context *ctxp;
+ assert(p);
+ apr_pool_userdata_get((void **)&ctxp, MP_KEY_CTX, p);
+ return(ctxp);
+}
+
+static apr_status_t modparrot_ctx_cleanup(void *data)
+{
+ modparrot_context *ctxp = (modparrot_context *)data;
+ release_ctx(ctxp);
+}
+
+static void modparrot_set_current_ctx(apr_pool_t *p, modparrot_context *ctxp)
+{
+ apr_pool_userdata_set(ctxp, MP_KEY_CTX, modparrot_ctx_cleanup, p);
+}
+
+static modparrot_context *init_ctx(server_rec *s, apr_pool_t *p)
+{
+ Parrot_Interp interp;
+ modparrot_context *ctxp = (modparrot_context *)NULL;
modparrot_srv_config *cfg;
- int conn_idx, ctx_idx;
cfg = ap_get_module_config(s->module_config, &parrot_module);
-#ifdef MPM_IS_THREADED
- if (c) {
- conn_idx = CONN_CTX_INDEX(c);
- ctx_idx = conn_ctx[conn_idx];
- }
- else {
- conn_idx = -1; /* unused */
- ctx_idx = MP_CTX_ANY;
- }
-#else /* MPM_IS_THREADED */
- ctx_idx = MP_CTX_ANY;
-#endif /* MPM_IS_THREADED */
-
- if ((ctxp = reserve_ctx(cfg->ctx_pool, ctx_idx))) {
- if (!ctxp->interp) {
- if (!(interp = modparrot_init(ctxp, s))) {
- MPLOG_ERROR(s,
- "init_ctx: interpreter initialization failed");
- return (modparrot_context *)NULL;
+ if (p) ctxp = modparrot_get_current_ctx(p);
+ if (!ctxp) {
+ if ((ctxp = reserve_ctx(cfg->ctx_pool, MP_CTX_ANY))) {
+ if (!ctxp->interp) {
+ if (!(interp = modparrot_init(ctxp, s))) {
+ MPLOG_ERROR(s,
+ "init_ctx: interpreter initialization failed");
+ return (modparrot_context *)NULL;
+ }
+ ctxp->interp = interp;
+ }
+ else {
+ interp = ctxp->interp;
}
- ctxp->interp = interp;
+
+ /* remember this context for the life of the pool */
+ if (p) modparrot_set_current_ctx(p, ctxp);
}
else {
- interp = ctxp->interp;
- }
-
-#ifdef MPM_IS_THREADED
- /* if we're in a connection, remember this context for future phases */
- if (c) {
- conn_ctx[conn_idx] = ctxp->pool_index;
+ MPLOG_ERROR(s, "init_ctx: no free contexts");
}
-#endif /* MPM_IS_THREADED */
+ }
- /* usually set s in a hook, but need it here for the config phase */
+ /* usually set s in a hook, but need it here for the config phase */
+ if (ctxp) {
ctxp->s = s;
}
- else {
- MPLOG_ERROR(s, "init_ctx: no free contexts");
- ctxp = (modparrot_context *)NULL;
- }
return(ctxp);
}
@@ -207,7 +208,7 @@
}
}
- if ((ctxp = init_ctx(s, NULL))) {
+ if ((ctxp = init_ctx(s, p))) {
mp_is_started = 1;
}
else {
@@ -215,11 +216,6 @@
return NULL;
}
- /* we assume that the passed in pool is the configuration pool. we'll use
- * this for early startups, but it will be overwritten by later handlers.
- */
- ctxp->pconf = p;
-
return(ctxp);
}
@@ -283,7 +279,7 @@
modparrot_context *ctxp;
/* initialize context */
- if (!(ctxp = init_ctx(r->server, r->connection))) {
+ if (!(ctxp = init_ctx(r->server, r->connection->pool))) {
MPLOG_ERROR(r->server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -291,9 +287,6 @@
/* we're FIRST, so reset the module index */
ctxp->module_index = -1;
- /* clean up */
- release_ctx(ctxp);
-
return DECLINED;
}
@@ -302,7 +295,7 @@
modparrot_context *ctxp;
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -310,9 +303,6 @@
/* we're REALLY_FIRST, so reset the module index */
ctxp->module_index = -1;
- /* clean up */
- release_ctx(ctxp);
-
/* we only do setup */
return DECLINED;
}
@@ -330,7 +320,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(ci->data.r->server, ci->data.r->connection))) {
+ if (!(ctxp = init_ctx(ci->data.r->server, ci->data.r->pool))) {
MPLOG_ERROR(ci->data.r->server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -350,13 +340,7 @@
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 */
+ * context and release it here. until that happens, this is a no-op. */
return APR_SUCCESS;
}
@@ -372,7 +356,7 @@
Parrot_PMC sub; \
int status; \
/* initialize context */ \
- if (!(ctxp = init_ctx(r->server, r->connection))) { \
+ if (!(ctxp = init_ctx(r->server, r->connection->pool))) { \
MPLOG_ERROR(r->server, "context initialization failed"); \
return HTTP_INTERNAL_SERVER_ERROR; \
} \
@@ -408,8 +392,6 @@
modp->name); \
status = HTTP_INTERNAL_SERVER_ERROR; \
} \
- /* clean up */ \
- release_ctx(ctxp); \
/* tell apache we're done */ \
return status; \
}
@@ -436,7 +418,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -465,9 +447,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
@@ -477,7 +456,7 @@
modparrot_context *ctxp;
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -485,9 +464,6 @@
/* we're REALLY_FIRST, so reset the module index */
ctxp->module_index = -1;
- /* clean up */
- release_ctx(ctxp);
-
/* we only do setup */
return DECLINED;
}
@@ -502,7 +478,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -527,9 +503,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
@@ -551,14 +524,11 @@
#ifdef MPM_IS_THREADED
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &hard_thread_limit);
ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads);
- /* an APR array is overkill for a static array, so alloc it ourselves */
- conn_ctx = (int *)apr_pcalloc(p, sizeof(int) * max_threads);
#else /* MPM_IS_THREADED */
hard_thread_limit = 1;
max_threads = 1;
#endif /* MPM_IS_THREADED */
- /* clean up */
release_ctx(ctxp);
}
@@ -595,10 +565,8 @@
"child_init_handler", &status)) {
MPLOG_ERRORF(s, "no child_init metahandler found for module '%s'",
modp->name);
- return;
}
- /* clean up */
release_ctx(ctxp);
}
@@ -608,7 +576,7 @@
modparrot_context *ctxp;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, ptemp))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -616,9 +584,6 @@
/* we're FIRST, so reset the module index */
ctxp->module_index = -1;
- /* clean up */
- release_ctx(ctxp);
-
/* we only do setup */
return DECLINED;
}
@@ -634,7 +599,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, ptemp))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -661,9 +626,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
@@ -680,9 +642,10 @@
mpcfg = ap_get_module_config(s->module_config, &parrot_module);
if (mpcfg->option_flags & MP_OPT_ENABLE) {
- if (!(ctxp = modparrot_startup(pconf, s, NULL))) {
+ if (!(ctxp = modparrot_startup(ptemp, s, NULL))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
+ ctxp->pconf = pconf;
parent_interp = ctxp->interp;
/* we're FIRST, so reset the module index */
@@ -704,9 +667,10 @@
vscfg = ap_get_module_config(vs->module_config, &parrot_module);
if (!(vscfg->option_flags & MP_OPT_ENABLE)) continue;
if (vscfg->option_flags & MP_OPT_PARENT) {
- if (!(vsctxp = modparrot_startup(pconf, vs, parent_interp))) {
+ if (!(vsctxp = modparrot_startup(ptemp, vs, parent_interp))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
+ vsctxp->pconf = pconf;
/* load ParrotLoad files */
modparrot_load_files(vsctxp->interp, vs, vscfg->preload);
@@ -715,9 +679,6 @@
if (!(vscfg->option_flags & MP_OPT_TRACE_INIT)) {
Parrot_set_trace(vsctxp->interp, vscfg->trace_flags);
}
-
- /* clean up */
- release_ctx(vsctxp);
}
else {
/* XXX is this check redundant (MP_OPT_ENABLE is checked above) */
@@ -731,9 +692,6 @@
}
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done -- open_logs handler must return OK */
return OK;
}
@@ -749,7 +707,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, ptemp))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -776,9 +734,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c (original)
+++ mod_parrot/trunk/src/modparrot_config.c Fri Dec 5 10:10:07 2008
@@ -204,13 +204,11 @@
cfg = GET_SERVER_CONFIG(cmd);
/* this will start the interpreter if necessary and return a context */
- ctxp = modparrot_startup(cmd->pool, cmd->server, NULL);
+ ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL);
+ ctxp->pconf = cmd->pool;
modparrot_load_file(ctxp->interp, cmd->server, path);
- /* clean up */
- release_ctx(ctxp);
-
return NULL;
}
Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c (original)
+++ mod_parrot/trunk/src/module.c Fri Dec 5 10:10:07 2008
@@ -130,7 +130,8 @@
int ret;
/* mod_parrot specific stuff */
- ctxp = modparrot_startup(cmd->pool, cmd->server, NULL);
+ ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL);
+ ctxp->pconf = cmd->pool;
/* create/fetch module server config */
srvcfg = (modparrot_module_config *)ap_get_module_config(
@@ -171,7 +172,6 @@
ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IPP",
dircfg->cfg, args);
- release_ctx(ctxp);
return NULL;
}