[svn:mod_parrot] r600 - in mod_parrot/trunk: include lib src
[email protected] Sun, 1 Feb 2009 11:15:09 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Sun Feb 1 11:15:08 2009
New Revision: 600
Modified:
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/include/modparrot_config.h
mod_parrot/trunk/lib/mod_parrot.pir
mod_parrot/trunk/src/context.c
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/modparrot_config.c
mod_parrot/trunk/src/module.c
Log:
named context pools part 1
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Sun Feb 1 11:15:08 2009
@@ -64,6 +64,7 @@
/* per-interpreter context */
struct modparrot_context
{
+ apr_array_header_t *ctx_pool; /* the pool containing this context */
Parrot_Interp interp; /* this context's interpreter */
Parrot_Interp parent_interp; /* parent interpreter */
long count; /* number of interpreter invocations */
@@ -110,7 +111,7 @@
void release_ctx(modparrot_context *);
modparrot_context *get_interp_ctx(Parrot_Interp);
void set_interp_ctx(Parrot_Interp, modparrot_context *);
-modparrot_context *modparrot_startup(apr_pool_t *, server_rec *, Parrot_Interp);
+modparrot_context *modparrot_startup(apr_pool_t *, server_rec *, Parrot_Interp, const char *);
void modparrot_load_file(Parrot_Interp, server_rec *, const char *);
module *modparrot_add_module(Parrot_Interp, apr_pool_t *, const char *, char *,
Parrot_PMC, Parrot_PMC);
@@ -118,6 +119,8 @@
void modparrot_set_current_ctx(apr_pool_t *, modparrot_context *);
apr_size_t modparrot_request_read(request_rec *, char *, apr_size_t);
Parrot_PMC modparrot_wrap_apache_type(Parrot_Interp, char *, char *, void *);
+apr_array_header_t *modparrot_get_named_ctx_pool(const char *);
+void modparrot_set_named_ctx_pool(const char *, apr_array_header_t *);
/* macros for wrapping apache types */
#define modparrot_wrap_apr_pool(i, x) \
Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h (original)
+++ mod_parrot/trunk/include/modparrot_config.h Sun Feb 1 11:15:08 2009
@@ -87,6 +87,8 @@
struct modparrot_module_info
{
+ char *ctx_pool_name; /* default context pool name for this module */
+ apr_array_header_t *ctx_pool; /* cached pointer to default context pool */
Parrot_PMC server_create_sub;
Parrot_PMC server_merge_sub;
Parrot_PMC dir_create_sub;
@@ -154,7 +156,7 @@
const char *modparrot_cmd_debug(cmd_parms *, void *, const char *);
const char *modparrot_cmd_language(cmd_parms *, void *, const char *);
const char *modparrot_cmd_load(cmd_parms *, void *, const char *);
-const char *modparrot_cmd_load_immediate(cmd_parms *, void *, const char *);
+const char *modparrot_cmd_load_immediate(cmd_parms *, void *, const char *, const char *);
const char *modparrot_cmd_include_path(cmd_parms *, void *, const char *);
const char *modparrot_cmd_lib_path(cmd_parms *, void *, const char *);
const char *modparrot_cmd_dynext_path(cmd_parms *, void *, const char *);
Modified: mod_parrot/trunk/lib/mod_parrot.pir
==============================================================================
--- mod_parrot/trunk/lib/mod_parrot.pir (original)
+++ mod_parrot/trunk/lib/mod_parrot.pir Sun Feb 1 11:15:08 2009
@@ -134,6 +134,7 @@
# load required libraries
load_bytecode 'P6object.pbc'
+ load_bytecode 'ModParrot/Constants.pbc'
load_bytecode 'ModParrot/Interpreter.pbc'
load_bytecode 'ModParrot/Context.pbc'
load_bytecode 'ModParrot/Apache/Constants.pbc'
Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c (original)
+++ mod_parrot/trunk/src/context.c Sun Feb 1 11:15:08 2009
@@ -57,6 +57,7 @@
for (i = 0; i < num; i++) {
ctx = (*(modparrot_context **)apr_array_push(ctx_pool) =
(modparrot_context *)apr_pcalloc(p, sizeof(modparrot_context)));
+ ctx->ctx_pool = ctx_pool;
ctx->parent_interp = parent_interp;
}
@@ -215,3 +216,16 @@
MP_TRACE_c(mp_globals.base_server, "binding context %p to APR pool %p", ctxp, p);
apr_pool_userdata_set(ctxp, MP_KEY_CTX, modparrot_ctx_cleanup, p);
}
+
+void modparrot_set_named_ctx_pool(const char *name, apr_array_header_t *cp)
+{
+ apr_hash_set(mp_globals.module_hash, name, APR_HASH_KEY_STRING, cp);
+}
+
+apr_array_header_t *modparrot_get_named_ctx_pool(const char *name)
+{
+ apr_array_header_t *cp;
+
+ cp = apr_hash_get(mp_globals.module_hash, name, APR_HASH_KEY_STRING);
+ return cp;
+}
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Sun Feb 1 11:15:08 2009
@@ -120,7 +120,8 @@
if (cfg->trace_flags == -1) cfg->trace_flags = 0;
/* initialize interpreter */
- interp = modparrot_init_interpreter(ctx->parent_interp);
+ interp = modparrot_init_interpreter(mp_globals.root_interp);
+ if (!mp_globals.root_interp) mp_globals.root_interp = interp;
/* enable tracing */
Parrot_set_trace(interp, (cfg->option_flags & MP_OPT_TRACE_INIT) ?
@@ -172,7 +173,8 @@
return(interp);
}
-static modparrot_context *init_ctx(server_rec *s, apr_pool_t *p)
+static modparrot_context *init_ctx(server_rec *s, apr_pool_t *p,
+ apr_array_header_t *ctx_pool)
{
Parrot_Interp interp;
modparrot_context *ctxp = (modparrot_context *)NULL;
@@ -180,9 +182,17 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
+ /* grab the current context... */
if (p) ctxp = modparrot_get_current_ctx(p);
+
+ /* ...but ignore it if it doesn't belong to the requested context pool */
+ if (ctxp && ctx_pool) {
+ if (ctxp->ctx_pool != ctx_pool) ctxp = NULL;
+ }
+
if (!ctxp) {
- if ((ctxp = reserve_ctx(cfg->ctx_pool, MP_CTX_ANY))) {
+ apr_array_header_t *cp = ctx_pool ? ctx_pool : cfg->ctx_pool;
+ if ((ctxp = reserve_ctx(cp, MP_CTX_ANY))) {
if (!ctxp->interp) {
if (!(interp = modparrot_init(ctxp, s))) {
MPLOG_ERROR(s,
@@ -195,7 +205,7 @@
interp = ctxp->interp;
}
- /* remember this context for the life of the pool */
+ /* remember this context for next time */
if (p) modparrot_set_current_ctx(p, ctxp);
}
else {
@@ -215,24 +225,42 @@
/* public interface for starting an interpreter */
modparrot_context *modparrot_startup(apr_pool_t *p, server_rec *s,
- Parrot_Interp parent_interp)
+ Parrot_Interp parent_interp, const char *pool_name)
{
modparrot_context *ctxp;
modparrot_srv_config *cfg;
+ apr_array_header_t *ctx_pool = NULL;
+ const char *name;
cfg = ap_get_module_config(s->module_config, &parrot_module);
if (!mp_globals.is_started) mp_globals.base_server = s;
- if (!mp_globals.is_started || (!cfg->ctx_pool && s->is_virtual)) {
- if (!(cfg->ctx_pool = mp_ctx_pool_init(p, parent_interp, 1))) {
+ name = pool_name ? pool_name : "default";
+ if (mp_globals.is_started) {
+ ctx_pool = modparrot_get_named_ctx_pool(name);
+ }
+
+ if (!ctx_pool) {
+ if (!(ctx_pool = mp_ctx_pool_init(p, parent_interp, 1))) {
MPLOG_ERROR(s, "context pool creation failed");
return NULL;
}
+ /* if server doesn't have a context pool, assign this one */
+ if (!cfg->ctx_pool) cfg->ctx_pool = ctx_pool;
+
+ /* name the pool so we can reference it later */
+ modparrot_set_named_ctx_pool(name, cfg->ctx_pool);
+ MP_TRACE_c(s, "modparrot_startup: context pool %p is named '%s'", ctx_pool, name);
}
- if ((ctxp = init_ctx(s, p))) {
- mp_globals.is_started = 1;
+ MP_TRACE_c(s, "modparrot_startup: using context pool %p (%s)", ctx_pool, name);
+
+ /* grab a context from the pool */
+ if ((ctxp = init_ctx(s, p, ctx_pool))) {
+ if (!mp_globals.is_started) {
+ mp_globals.is_started = 1;
+ }
}
else {
MPLOG_ERROR(s, "context initialization failed");
@@ -304,7 +332,7 @@
MP_TRACE_h(r->server, "in modparrot_request_phase_handler");
/* initialize context */
- if (!(ctxp = init_ctx(r->server, r->connection->pool))) {
+ if (!(ctxp = init_ctx(r->server, r->connection->pool, NULL))) {
MPLOG_ERROR(r->server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -325,7 +353,7 @@
MP_TRACE_h(c->base_server, "in modparrot_pre_connection_handler");
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c->pool))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool, NULL))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -353,7 +381,7 @@
int status;
/* initialize context */
- if (!(ctxp = init_ctx(ci->s, ci->pool))) {
+ if (!(ctxp = init_ctx(ci->s, ci->pool, NULL))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -381,7 +409,7 @@
int status; \
MP_TRACE_h(r->server, "in modparrot_meta_%s", #hname); \
/* initialize context */ \
- if (!(ctxp = init_ctx(r->server, r->connection->pool))) { \
+ if (!(ctxp = init_ctx(r->server, r->connection->pool, NULL))) { \
MPLOG_ERROR(r->server, "context initialization failed"); \
return HTTP_INTERNAL_SERVER_ERROR; \
} \
@@ -446,7 +474,7 @@
MP_TRACE_h(c->base_server, "in modparrot_meta_pre_connection_handler");
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c->pool))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool, NULL))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -483,7 +511,7 @@
MP_TRACE_h(c->base_server, "in modparrot_process_connection_handler");
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c->pool))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool, NULL))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -510,7 +538,7 @@
MP_TRACE_h(c->base_server, "in modparrot_meta_process_connection_handler");
/* initialize context */
- if (!(ctxp = init_ctx(c->base_server, c->pool))) {
+ if (!(ctxp = init_ctx(c->base_server, c->pool, NULL))) {
MPLOG_ERROR(c->base_server, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -547,7 +575,7 @@
MP_TRACE_h(s, "in modparrot_child_init_handler");
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, NULL, NULL))) {
MPLOG_ERROR(s, "context initialization failed");
return;
}
@@ -583,7 +611,7 @@
MP_TRACE_h(s, "in modparrot_meta_child_init_handler");
/* initialize context */
- if (!(ctxp = init_ctx(s, NULL))) {
+ if (!(ctxp = init_ctx(s, NULL, NULL))) {
MPLOG_ERROR(s, "context initialization failed");
return;
}
@@ -622,7 +650,7 @@
ap_add_version_component(pconf, "mod_parrot/" MODPARROT_VERSION);
/* initialize context */
- if (!(ctxp = init_ctx(s, ptemp))) {
+ if (!(ctxp = init_ctx(s, ptemp, NULL))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -650,7 +678,7 @@
MP_TRACE_h(s, "in modparrot_meta_post_config_handler");
/* initialize context */
- if (!(ctxp = init_ctx(s, ptemp))) {
+ if (!(ctxp = init_ctx(s, ptemp, NULL))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -695,7 +723,7 @@
mpcfg = ap_get_module_config(s->module_config, &parrot_module);
if (mpcfg->option_flags & MP_OPT_ENABLE) {
- if (!(ctxp = modparrot_startup(ptemp, s, NULL))) {
+ if (!(ctxp = modparrot_startup(ptemp, s, NULL, NULL))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
ctxp->pconf = pconf;
@@ -723,7 +751,7 @@
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(ptemp, vs, parent_interp))) {
+ if (!(vsctxp = modparrot_startup(ptemp, vs, parent_interp, NULL))) {
return HTTP_INTERNAL_SERVER_ERROR;
}
vsctxp->pconf = pconf;
@@ -771,7 +799,7 @@
MP_TRACE_h(s, "in modparrot_meta_open_logs_handler");
/* initialize context */
- if (!(ctxp = init_ctx(s, ptemp))) {
+ if (!(ctxp = init_ctx(s, ptemp, NULL))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
@@ -881,7 +909,7 @@
RSRC_CONF,
"preload Parrot code"
),
- AP_INIT_ITERATE(
+ AP_INIT_TAKE12(
"ParrotLoadImmediate",
modparrot_cmd_load_immediate,
NULL,
Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c (original)
+++ mod_parrot/trunk/src/modparrot_config.c Sun Feb 1 11:15:08 2009
@@ -240,7 +240,7 @@
}
const char *modparrot_cmd_load_immediate(cmd_parms *cmd, void *mconfig,
- const char *path)
+ const char *path, const char *pool_name)
{
modparrot_srv_config *cfg;
modparrot_context *ctxp;
@@ -248,7 +248,7 @@
cfg = GET_SERVER_CONFIG(cmd);
/* this will start the interpreter if necessary and return a context */
- ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL);
+ ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL, pool_name);
ctxp->pconf = cmd->pool;
modparrot_load_file(ctxp->interp, cmd->server, path);
Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c (original)
+++ mod_parrot/trunk/src/module.c Sun Feb 1 11:15:08 2009
@@ -208,7 +208,7 @@
cmd->directive->directive);
/* mod_parrot specific stuff */
- ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL);
+ ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL, NULL);
ctxp->pconf = cmd->pool;
/* create a ModParrot;Apache;CmdParms object to pass to the handlers */