Author: jhorwitz
Date: Tue Dec 25 20:19:30 2007
New Revision: 295
Modified:
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/include/modparrot_config.h
mod_parrot/trunk/src/context.c
mod_parrot/trunk/src/mod_parrot.c
mod_parrot/trunk/src/modparrot_config.c
mod_parrot/trunk/src/parrot_util.c
Log:
start interpreter earlier, during open_logs phase
add 'Parent' option for specifying per-server or per-process context pools
register cleanup handlers for context pools so we can survive a restart
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Tue Dec 25 20:19:30 2007
@@ -52,7 +52,7 @@
typedef struct modparrot_context modparrot_context;
/* misc prototypes */
-Parrot_Interp modparrot_init_interpreter(void);
+Parrot_Interp modparrot_init_interpreter(Parrot_Interp);
int modparrot_load_bytecode(Parrot_Interp, char *);
void modparrot_destroy_interpreter(Parrot_Interp);
int modparrot_call_sub(Parrot_Interp, char *, char *);
Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h (original)
+++ mod_parrot/trunk/include/modparrot_config.h Tue Dec 25 20:19:30 2007
@@ -17,6 +17,9 @@
#include "apr_tables.h"
+/* per-server options */
+#define MP_OPT_PARENT 1
+
/* configuration */
struct modparrot_handler_info
{
@@ -31,6 +34,7 @@
apr_array_header_t *ctx_pool;
char *init_path;
int trace_flags;
+ int option_flags;
char *include_path;
apr_array_header_t *preload;
apr_table_t *handler_map;
Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c (original)
+++ mod_parrot/trunk/src/context.c Tue Dec 25 20:19:30 2007
@@ -53,13 +53,13 @@
/* destroy pool of contexts */
void mp_ctx_pool_destroy(apr_array_header_t *ctx_pool)
{
- modparrot_context *ctx;
+ modparrot_context **ctxpp;
if (!ctx_pool) return;
/* pop each context off the list and destroy its interpreter */
- while (ctx = apr_array_pop(ctx_pool)) {
- if (ctx->interp) modparrot_destroy_interpreter(ctx->interp);
+ while (ctxpp = apr_array_pop(ctx_pool)) {
+ if ((*ctxpp)->interp) modparrot_destroy_interpreter((*ctxpp)->interp);
}
/* apache will take care of destroying the actual context pool array */
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Tue Dec 25 20:19:30 2007
@@ -36,7 +36,7 @@
#include "modparrot_config.h"
#include "modparrot_log.h"
-#define MODPARROT_VERSION "0.3"
+#define MODPARROT_VERSION "0.4"
#define DEFAULT_HANDLER "handler"
#define SHOULD_HANDLE(x) (x->handler ? \
@@ -57,7 +57,7 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
/* initialize interpreter */
- interp = modparrot_init_interpreter();
+ interp = modparrot_init_interpreter(NULL);
Parrot_set_trace(interp, cfg->trace_flags);
/* run initialization code */
@@ -115,7 +115,7 @@
if (!ctxp->interp) {
if (!(interp = modparrot_init(ctxp, s))) {
MPLOG_ERROR(s,
- "modparrot_ctx_init: interpreter initialization failed");
+ "init_ctx: interpreter initialization failed");
return (modparrot_context *)NULL;
}
ctxp->interp = interp;
@@ -125,7 +125,7 @@
}
}
else {
- MPLOG_ERROR(s, "modparrot_ctx_init: no free contexts");
+ MPLOG_ERROR(s, "init_ctx: no free contexts");
ctxp = (modparrot_context *)NULL;
}
@@ -837,19 +837,19 @@
apr_pool_t *ptemp, server_rec *s)
{
modparrot_srv_config *cfg;
- modparrot_context *ctxp;
+ modparrot_context *ctxp, *vsctxp;
int handler_status;
char *sub, *hll;
+ server_rec *vs;
/* get apache configs */
cfg = ap_get_module_config(s->module_config, &parrot_module);
- /* if not our handler, return OK (open_logs must return OK) */
- if (!cfg->open_logs_handler) {
- return OK;
+ /* ALWAYS INIT THE CONTEXT POOL AND START THE INTERPRETER HERE! */
+ if (!(cfg->ctx_pool = mp_ctx_pool_init(pconf, 1))) {
+ MPLOG_ERROR(s, "context pool creation failed");
+ return HTTP_INTERNAL_SERVER_ERROR;
}
-
- /* initialize context */
if (!(ctxp = init_ctx(s))) {
MPLOG_ERROR(s, "context initialization failed");
return HTTP_INTERNAL_SERVER_ERROR;
@@ -860,6 +860,34 @@
ctxp->ptemp = ptemp;
ctxp->s = s;
+ /* init per-server (MP_OPT_PARENT) or per-process (default) pools */
+ for (vs = s->next; vs; vs = vs->next) {
+ modparrot_srv_config *vscfg;
+ vscfg = ap_get_module_config(vs->module_config, &parrot_module);
+ if (vscfg->option_flags | MP_OPT_PARENT) {
+ if (!(vscfg->ctx_pool = mp_ctx_pool_init(pconf, 1))) {
+ MPLOG_ERROR(s, "context pool creation failed");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ if (!(vsctxp = init_ctx(vs))) {
+ MPLOG_ERROR(vs, "context initialization failed");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ }
+ else {
+ vscfg->ctx_pool = cfg->ctx_pool;
+ }
+ vsctxp->pconf = pconf;
+ vsctxp->plog = plog;
+ vsctxp->ptemp = ptemp;
+ vsctxp->s = vs;
+ }
+
+ /* if not our handler, return OK (open_logs must return OK) */
+ if (!cfg->open_logs_handler) {
+ return OK;
+ }
+
/* call HLL handler */
sub = "open_logs_handler";
hll = cfg->open_logs_handler->hll ? cfg->open_logs_handler->hll : "PIR";
Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c (original)
+++ mod_parrot/trunk/src/modparrot_config.c Tue Dec 25 20:19:30 2007
@@ -43,6 +43,7 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
mp_ctx_pool_destroy(cfg->ctx_pool);
+ cfg->ctx_pool = NULL;
return APR_SUCCESS;
}
@@ -54,18 +55,13 @@
cfg = (modparrot_srv_config *)apr_pcalloc(p, sizeof(modparrot_srv_config));
cfg->pool = p;
cfg->trace_flags = 0;
+ cfg->option_flags = 0;
cfg->init_path = MODPARROT_DEFAULT_INIT;
cfg->preload = apr_array_make(p, 2, sizeof(modparrot_handler_info));
cfg->include_path = NULL;
cfg->type_map = apr_table_make(p, 2);
cfg->handler_map = apr_table_make(p, 2);
- /* initialize context pool */
- if (!(cfg->ctx_pool = mp_ctx_pool_init(p, 2))) {
- MPLOG_ERROR(s, "context pool creation failed");
- return NULL;
- }
-
/* destroy context pool on cleanup */
apr_pool_cleanup_register(p, s, modparrot_cleanup, modparrot_cleanup);
@@ -178,7 +174,12 @@
*/
int modparrot_set_option(modparrot_srv_config *cfg, char *option, int enable)
{
- /* XXX add option processing here */
+ if (!strncasecmp(option, "Parent", 6)) {
+ cfg->option_flags &= enable ? MP_OPT_PARENT : ~MP_OPT_PARENT;
+ }
+ else {
+ return 0;
+ }
return 1;
}
Modified: mod_parrot/trunk/src/parrot_util.c
==============================================================================
--- mod_parrot/trunk/src/parrot_util.c (original)
+++ mod_parrot/trunk/src/parrot_util.c Tue Dec 25 20:19:30 2007
@@ -67,13 +67,13 @@
return sub;
}
-Parrot_Interp modparrot_init_interpreter(void)
+Parrot_Interp modparrot_init_interpreter(Parrot_Interp parent)
{
Parrot_Interp interp;
Parrot_PackFile pf;
struct PackFile_Segment *seg;
- interp = Parrot_new(NULL);
+ interp = Parrot_new(parent);
imcc_init(interp);
pf = PackFile_new_dummy(interp, "mod_parrot_code");
return(interp);
@@ -86,9 +86,33 @@
return(1);
}
+/* stolen from parrot -- it's Parrot_exit() without the exit() */
+/* we should be able to do this with a Parrot API call, but not yet */
+static void modparrot_interp_cleanup(Parrot_Interp interp, int status)
+{
+
+ Parrot_block_DOD(interp);
+ Parrot_block_GC(interp);
+
+/* this isn't working right now */
+#if 1
+ handler_node_t *node = interp->exit_handler_list;
+ while (node) {
+ handler_node_t * const next = node->next;
+
+ (node->function)(interp, status, node->arg);
+ mem_sys_free(node);
+ node = next;
+ }
+#else
+ Parrot_really_destroy(interp, 0, NULL);
+#endif
+
+}
+
void modparrot_destroy_interpreter(Parrot_Interp interp)
{
- Parrot_destroy(interp);
+ modparrot_interp_cleanup(interp, 0);
}
int modparrot_call_sub(Parrot_Interp interp, char *namespace, char *name)
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.