[svn:mod_parrot] r517 - in mod_parrot/branches/userdata: include src
[email protected] Fri, 5 Dec 2008 08:51:44 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Fri Dec 5 08:51:43 2008
New Revision: 517
Modified:
mod_parrot/branches/userdata/include/mod_parrot.h
mod_parrot/branches/userdata/src/mod_parrot.c
mod_parrot/branches/userdata/src/modparrot_config.c
mod_parrot/branches/userdata/src/module.c
Log:
replaced connection maps with pool userdata.
works for prefork, breaks for threaded MPMs.
Modified: mod_parrot/branches/userdata/include/mod_parrot.h
==============================================================================
--- mod_parrot/branches/userdata/include/mod_parrot.h (original)
+++ mod_parrot/branches/userdata/include/mod_parrot.h Fri Dec 5 08:51:43 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/branches/userdata/src/mod_parrot.c
==============================================================================
--- mod_parrot/branches/userdata/src/mod_parrot.c (original)
+++ mod_parrot/branches/userdata/src/mod_parrot.c Fri Dec 5 08:51:43 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,56 @@
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;
+ 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 (!(ctxp = modparrot_get_current_ctx(p))) {
+ 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;
}
- ctxp->interp = interp;
+ else {
+ interp = ctxp->interp;
+ }
+
+ /* remember this context for the life of the pool */
+ modparrot_set_current_ctx(p, ctxp);
}
else {
- interp = ctxp->interp;
+ MPLOG_ERROR(s, "init_ctx: no free contexts");
}
-#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;
- }
-#endif /* MPM_IS_THREADED */
-
/* usually set s in a hook, but need it here for the config phase */
ctxp->s = s;
}
- else {
- MPLOG_ERROR(s, "init_ctx: no free contexts");
- ctxp = (modparrot_context *)NULL;
- }
return(ctxp);
}
@@ -207,7 +204,7 @@
}
}
- if ((ctxp = init_ctx(s, NULL))) {
+ if ((ctxp = init_ctx(s, p))) {
mp_is_started = 1;
}
else {
@@ -283,7 +280,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 +288,6 @@
/* we're FIRST, so reset the module index */
ctxp->module_index = -1;
- /* clean up */
- release_ctx(ctxp);
-
return DECLINED;
}
@@ -302,7 +296,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 +304,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 +321,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 +341,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 +357,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 +393,6 @@
modp->name); \
status = HTTP_INTERNAL_SERVER_ERROR; \
} \
- /* clean up */ \
- release_ctx(ctxp); \
/* tell apache we're done */ \
return status; \
}
@@ -436,7 +419,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 +448,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
@@ -477,7 +457,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 +465,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 +479,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 +504,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
@@ -539,7 +513,7 @@
modparrot_context *ctxp;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, p))) {
MPLOG_ERROR(s, "context initialization failed");
return;
}
@@ -551,15 +525,10 @@
#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);
}
/* XXX - how do we notify apache of failures with a void return??? */
@@ -573,7 +542,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, p))) {
MPLOG_ERROR(s, "context initialization failed");
return;
}
@@ -597,9 +566,6 @@
modp->name);
return;
}
-
- /* clean up */
- release_ctx(ctxp);
}
static int modparrot_post_config_handler(apr_pool_t *pconf, apr_pool_t *plog,
@@ -608,7 +574,7 @@
modparrot_context *ctxp;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, pconf))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -616,9 +582,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 +597,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, pconf))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -661,9 +624,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
@@ -715,9 +675,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 +688,6 @@
}
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done -- open_logs handler must return OK */
return OK;
}
@@ -749,7 +703,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, pconf))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -776,9 +730,6 @@
status = HTTP_INTERNAL_SERVER_ERROR;
}
- /* clean up */
- release_ctx(ctxp);
-
/* tell apache we're done */
return status;
}
Modified: mod_parrot/branches/userdata/src/modparrot_config.c
==============================================================================
--- mod_parrot/branches/userdata/src/modparrot_config.c (original)
+++ mod_parrot/branches/userdata/src/modparrot_config.c Fri Dec 5 08:51:43 2008
@@ -208,9 +208,6 @@
modparrot_load_file(ctxp->interp, cmd->server, path);
- /* clean up */
- release_ctx(ctxp);
-
return NULL;
}
Modified: mod_parrot/branches/userdata/src/module.c
==============================================================================
--- mod_parrot/branches/userdata/src/module.c (original)
+++ mod_parrot/branches/userdata/src/module.c Fri Dec 5 08:51:43 2008
@@ -171,7 +171,6 @@
ret = Parrot_call_sub_ret_int(ctxp->interp, data->func, "IPP",
dircfg->cfg, args);
- release_ctx(ctxp);
return NULL;
}