[svn:mod_parrot] r599 - in mod_parrot/trunk: include src
[email protected] Sun, 1 Feb 2009 08:42:06 -0800 (PST)
| Newsgroups | perl.cvs.mod_parrot |
|---|---|
| Message-ID | <[email protected]> |
Author: jhorwitz
Date: Sun Feb 1 08:42:05 2009
New Revision: 599
Modified:
mod_parrot/trunk/include/mod_parrot.h
mod_parrot/trunk/include/modparrot_config.h
mod_parrot/trunk/include/modparrot_log.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/module.c
mod_parrot/trunk/src/nci.c
Log:
store all globals in a single mp_globals structure
move HLL module metadata to mp_globals (removed from server config)
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 08:42:05 2009
@@ -45,6 +45,22 @@
/* we need to move things around to avoid this */
#include "modparrot_config.h"
+/* globals! */
+struct modparrot_globals
+{
+ apr_hash_t *module_hash;
+ apr_array_header_t *module_array;
+ apr_array_header_t *handler_modules[MP_HOOK_LAST];
+ apr_hash_t *ctx_pool_hash;
+ Parrot_Interp root_interp;
+ server_rec *base_server;
+ int is_started;
+ int debug_level;
+ int hard_thread_limit;
+ int max_threads;
+};
+typedef struct modparrot_globals modparrot_globals;
+
/* per-interpreter context */
struct modparrot_context
{
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 08:42:05 2009
@@ -123,9 +123,6 @@
char *lib_path;
char *so_path;
apr_array_header_t *preload;
- apr_array_header_t *module_array;
- apr_hash_t *module_hash;
- apr_array_header_t *handler_modules[MP_HOOK_LAST];
};
typedef struct modparrot_srv_config modparrot_srv_config;
Modified: mod_parrot/trunk/include/modparrot_log.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_log.h (original)
+++ mod_parrot/trunk/include/modparrot_log.h Sun Feb 1 08:42:05 2009
@@ -18,10 +18,6 @@
#ifndef _MODPARROT_LOG_H
#define _MODPARROT_LOG_H
-#ifndef HAVE_LOCAL_DEBUG_LEVEL
-extern int modparrot_debug_level;
-#endif /* HAVE_LOCAL_DEBUG_LEVEL */
-
#define MPLOG_WARN(s, msg) \
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "%s", msg)
@@ -57,10 +53,10 @@
#define MP_DEBUG_PARROT 8
#define MP_DEBUG_HLL 16
-#define MP_TRACE_h if (modparrot_debug_level & MP_DEBUG_HOOK) modparrot_trace
-#define MP_TRACE_c if (modparrot_debug_level & MP_DEBUG_CONTEXT) modparrot_trace
-#define MP_TRACE_p if (modparrot_debug_level & MP_DEBUG_PARROT) modparrot_trace
-#define MP_TRACE_m if (modparrot_debug_level & MP_DEBUG_MODULE) modparrot_trace
+#define MP_TRACE_h if (mp_globals.debug_level & MP_DEBUG_HOOK) modparrot_trace
+#define MP_TRACE_c if (mp_globals.debug_level & MP_DEBUG_CONTEXT) modparrot_trace
+#define MP_TRACE_p if (mp_globals.debug_level & MP_DEBUG_PARROT) modparrot_trace
+#define MP_TRACE_m if (mp_globals.debug_level & MP_DEBUG_MODULE) modparrot_trace
#else /* MODPARROT_DEBUG */
Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c (original)
+++ mod_parrot/trunk/src/context.c Sun Feb 1 08:42:05 2009
@@ -38,7 +38,7 @@
apr_thread_mutex_t *ctx_pool_mutex;
#endif /* MPM_IS_THREADED */
-extern server_rec *base_server;
+extern modparrot_globals mp_globals;
/* initialize pool of contexts */
apr_array_header_t * mp_ctx_pool_init(apr_pool_t *p,
@@ -48,7 +48,7 @@
apr_array_header_t *ctx_pool;
modparrot_context *ctx;
- MP_TRACE_c(base_server, "creating context pool of size %d", num);
+ MP_TRACE_c(mp_globals.base_server, "creating context pool of size %d", num);
if (!(ctx_pool = apr_array_make(p, num, sizeof(modparrot_context)))) {
return NULL;
@@ -67,7 +67,7 @@
}
#endif /* MPM_IS_THREADED */
- MP_TRACE_c(base_server, "created context pool %p (size %d)", ctx_pool, num);
+ MP_TRACE_c(mp_globals.base_server, "created context pool %p (size %d)", ctx_pool, num);
return ctx_pool;
}
@@ -79,7 +79,7 @@
if (!ctx_pool) return;
- MP_TRACE_c(base_server, "destroying context pool %p", ctx_pool);
+ MP_TRACE_c(mp_globals.base_server, "destroying context pool %p", ctx_pool);
/* pop each context off the list and destroy its interpreter */
#ifdef MPM_IS_THREADED
@@ -109,7 +109,7 @@
if (!ctx_pool) return NULL;
- MP_TRACE_c(base_server, "reserving a context from pool %p", ctx_pool);
+ MP_TRACE_c(mp_globals.base_server, "reserving a context from pool %p", ctx_pool);
#ifdef MPM_IS_THREADED
apr_thread_mutex_lock(ctx_pool_mutex);
@@ -139,7 +139,7 @@
MODPARROT_CTX_LOCK(ctxp); /* no threads here, just for consistency */
#endif /* MPM_IS_THREADED */
- MP_TRACE_c(base_server, "reserved context %p from pool %p", ctxp, ctx_pool);
+ MP_TRACE_c(mp_globals.base_server, "reserved context %p from pool %p", ctxp, ctx_pool);
return(ctxp);
}
@@ -147,7 +147,7 @@
/* releases a context back into the pool of available contexts */
void release_ctx(modparrot_context *ctxp)
{
- MP_TRACE_c(base_server, "releasing context %p", ctxp);
+ MP_TRACE_c(mp_globals.base_server, "releasing context %p", ctxp);
MODPARROT_CTX_UNLOCK(ctxp);
}
@@ -212,6 +212,6 @@
void modparrot_set_current_ctx(apr_pool_t *p, modparrot_context *ctxp)
{
- MP_TRACE_c(base_server, "binding context %p to APR pool %p", ctxp, p);
+ 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);
}
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 08:42:05 2009
@@ -40,7 +40,10 @@
#define MODPARROT_VERSION "0.5"
-#define NEXT_HANDLER_MODULE(x) (mpcfg->handler_modules[x] ? ((module **)mpcfg->module_array->elts)[((int *)mpcfg->handler_modules[x]->elts)[++(ctxp->module_index)]] : NULL);
+#define NEXT_HANDLER_MODULE(x) (mp_globals.handler_modules[x] ? ((module **)mp_globals.module_array->elts)[((int *)mp_globals.handler_modules[x]->elts)[++(ctxp->module_index)]] : NULL);
+
+/* a single structure for globals */
+modparrot_globals mp_globals;
/* declare our module */
extern module AP_MODULE_DECLARE_DATA parrot_module;
@@ -51,17 +54,22 @@
*/
Parrot_PMC Parrot_Class_instantiate(PARROT_INTERP, PMC *, PMC *init);
-/* have we started? this can be global since it's written to at startup */
-int mp_is_started = 0;
-
-/* thread info */
-int hard_thread_limit, max_threads;
-
-/* debug level */
-int modparrot_debug_level = 0;
+void modparrot_init_globals(apr_pool_t *p)
+{
+ int i;
-/* base server_rec for when we have no other way of obtaining it */
-server_rec *base_server = NULL;
+ mp_globals.is_started = 0;
+ mp_globals.debug_level = 0;
+ mp_globals.max_threads = 0;
+ mp_globals.hard_thread_limit = 0;
+ mp_globals.base_server = NULL;
+ mp_globals.module_hash = apr_hash_make(p);
+ mp_globals.module_array = apr_array_make(p, 1, sizeof(module *));;
+ mp_globals.ctx_pool_hash = apr_hash_make(p);
+ for (i = 0; i < MP_HOOK_LAST; i++) {
+ mp_globals.handler_modules[i] = NULL;
+ }
+}
void modparrot_trace(server_rec *s, const char *fmt, ...)
{
@@ -214,9 +222,9 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
- if (!mp_is_started) base_server = s;
+ if (!mp_globals.is_started) mp_globals.base_server = s;
- if (!mp_is_started || (!cfg->ctx_pool && s->is_virtual)) {
+ if (!mp_globals.is_started || (!cfg->ctx_pool && s->is_virtual)) {
if (!(cfg->ctx_pool = mp_ctx_pool_init(p, parent_interp, 1))) {
MPLOG_ERROR(s, "context pool creation failed");
return NULL;
@@ -224,7 +232,7 @@
}
if ((ctxp = init_ctx(s, p))) {
- mp_is_started = 1;
+ mp_globals.is_started = 1;
}
else {
MPLOG_ERROR(s, "context initialization failed");
@@ -549,11 +557,11 @@
/* query apache mpm for thread limits */
#ifdef MPM_IS_THREADED
- ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &hard_thread_limit);
- ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads);
+ ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &mp_globals.hard_thread_limit);
+ ap_mpm_query(AP_MPMQ_MAX_THREADS, &mp_globals.max_threads);
#else /* MPM_IS_THREADED */
- hard_thread_limit = 1;
- max_threads = 1;
+ mp_globals.hard_thread_limit = 1;
+ mp_globals.max_threads = 1;
#endif /* MPM_IS_THREADED */
/* set the most specific pool */
@@ -797,7 +805,10 @@
static void register_hooks(apr_pool_t *p)
{
- MP_TRACE_h(base_server, "in register_hooks");
+ MP_TRACE_h(mp_globals.base_server, "in register_hooks");
+
+ /* initialize globals before we do anything else */
+ modparrot_init_globals(p);
/* this allows <IfDefine MODPARROT> blocks */
*(char **)apr_array_push(ap_server_config_defines) =
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 08:42:05 2009
@@ -41,7 +41,7 @@
#define DEFAULT_OPTION_FLAGS (MP_OPT_ENABLE)
extern module AP_MODULE_DECLARE_DATA parrot_module;
-extern int mp_is_started;
+extern modparrot_globals mp_globals;
static apr_status_t modparrot_cleanup(void *data)
{
@@ -54,12 +54,12 @@
/* destroy context pools and interpreters */
mp_ctx_pool_destroy(cfg->ctx_pool);
cfg->ctx_pool = NULL;
- mp_is_started = 0;
+ mp_globals.is_started = 0;
/* reset module configs so we recreate them on restart */
- for (i = 0; i < cfg->module_array->nelts; i++) {
+ for (i = 0; i < mp_globals.module_array->nelts; i++) {
modparrot_module_config *modcfg;
- modcfg = ((modparrot_module_config **)cfg->module_array->elts)[i];
+ modcfg = ((modparrot_module_config **)mp_globals.module_array->elts)[i];
modcfg->cfg = NULL;
}
return APR_SUCCESS;
@@ -82,11 +82,6 @@
cfg->include_path = NULL;
cfg->lib_path = NULL;
cfg->dynext_path = NULL;
- cfg->module_array = apr_array_make(p, 2, sizeof(module *));
- cfg->module_hash = apr_hash_make(p);
- for (i = 0; i < MP_HOOK_LAST; i++) {
- cfg->handler_modules[i] = NULL;
- }
/* unfortunately, some OS-specific stuff */
#if (__FreeBSD__)
@@ -145,15 +140,6 @@
merged->option_flags &= ~(newcfg->disable_option_flags);
}
- /* modules hash and array are only set in main server, so just copy */
- /* XXX need to enforce this */
- merged->module_hash = apr_hash_copy(p, basecfg->module_hash);
- merged->module_array = apr_array_copy(p, basecfg->module_array);
- for (i = 0; i < MP_HOOK_LAST; i++) {
- merged->handler_modules[i] = basecfg->handler_modules[i] ?
- apr_array_copy(p, basecfg->handler_modules[i]) : NULL;
- }
-
/* inherit the init_path, since it's rare it will change for a vhost */
merged->init_path = newcfg->init_path ?
newcfg->init_path : basecfg->init_path;
@@ -225,7 +211,7 @@
MPLOG_WARN(cmd->server, "WARNING: ignoring ParrotDebugLevel in VirtualHost");
}
else {
- modparrot_debug_level = atoi(f);
+ mp_globals.debug_level = atoi(f);
}
return NULL;
Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c (original)
+++ mod_parrot/trunk/src/module.c Sun Feb 1 08:42:05 2009
@@ -34,10 +34,9 @@
#include "modparrot_config.h"
#include "modparrot_log.h"
-extern module AP_MODULE_DECLARE_DATA parrot_module;
AP_DECLARE_DATA extern module *ap_top_module;
-
-extern server_rec *base_server;
+extern module AP_MODULE_DECLARE_DATA parrot_module;
+extern modparrot_globals mp_globals;
static apr_status_t modparrot_remove_module(void *data)
{
@@ -79,8 +78,8 @@
modparrot_module_config *newcfg =(modparrot_module_config *)new;
modparrot_module_config *mergedcfg = modparrot_create_module_config(p);
modparrot_srv_config *mpcfg =
- ap_get_module_config(base_server->module_config, &parrot_module);
- module *modp = apr_hash_get(mpcfg->module_hash, basecfg->name,
+ ap_get_module_config(mp_globals.base_server->module_config, &parrot_module);
+ module *modp = apr_hash_get(mp_globals.module_hash, basecfg->name,
APR_HASH_KEY_STRING);
modparrot_module_info *minfo = modp->dynamic_load_handle;
@@ -102,7 +101,7 @@
}
/* call merge routine */
- MP_TRACE_m(base_server, "calling server_merge for module '%s'", modp->name);
+ MP_TRACE_m(mp_globals.base_server, "calling server_merge for module '%s'", modp->name);
mergedcfg->cfg = Parrot_call_sub(ctxp->interp, minfo->server_merge_sub,
"PPP", basecfg->cfg, newcfg->cfg);
@@ -126,8 +125,8 @@
modparrot_module_config *newcfg =(modparrot_module_config *)new;
modparrot_module_config *mergedcfg = modparrot_create_module_config(p);
modparrot_srv_config *mpcfg =
- ap_get_module_config(base_server->module_config, &parrot_module);
- module *modp = apr_hash_get(mpcfg->module_hash, basecfg->name,
+ ap_get_module_config(mp_globals.base_server->module_config, &parrot_module);
+ module *modp = apr_hash_get(mp_globals.module_hash, basecfg->name,
APR_HASH_KEY_STRING);
modparrot_module_info *minfo = modp->dynamic_load_handle;
@@ -152,7 +151,7 @@
}
/* call merge routine */
- MP_TRACE_m(base_server, "calling dir_merge for module '%s'", modp->name);
+ MP_TRACE_m(mp_globals.base_server, "calling dir_merge for module '%s'", modp->name);
mergedcfg->cfg = Parrot_call_sub(ctxp->interp, minfo->dir_merge_sub,
"PPP", basecfg->cfg, newcfg->cfg);
@@ -311,21 +310,23 @@
static int module_index = 0;
/* this assumes we're called in the same order modules were added */
- mpcfg = ap_get_module_config(base_server->module_config, &parrot_module);
- modp = ((module **)mpcfg->module_array->elts)[module_index];
+ mpcfg = ap_get_module_config(mp_globals.base_server->module_config,
+ &parrot_module);
+ modp = ((module **)mp_globals.module_array->elts)[module_index];
minfo = modp->dynamic_load_handle;
for (i = 0; i < MP_HOOK_LAST; i++) {
if (minfo->hooks[i]) {
int *pidx;
/* add module to handler index so meta handlers know who we are */
- if (!mpcfg->handler_modules[i]) {
- mpcfg->handler_modules[i] = apr_array_make(p, 1, sizeof(int));
+ if (!mp_globals.handler_modules[i]) {
+ mp_globals.handler_modules[i] =
+ apr_array_make(p, 1, sizeof(int));
}
- pidx = (int *)apr_array_push(mpcfg->handler_modules[i]);
+ pidx = (int *)apr_array_push(mp_globals.handler_modules[i]);
*pidx = module_index;
- MP_TRACE_m(base_server, "registering hook %d for module '%s'", i, modp->name);
+ MP_TRACE_m(mp_globals.base_server, "registering hook %d for module '%s'", i, modp->name);
/* register this hook with apache */
switch(i) {
@@ -577,10 +578,10 @@
modp->register_hooks = register_meta_hooks;
/* module_array lets us access modules in sequence */
- *(module **)apr_array_push(mpcfg->module_array) = modp;
+ *(module **)apr_array_push(mp_globals.module_array) = modp;
/* module_hash lets us access modules by name */
- apr_hash_set(mpcfg->module_hash, (char *)apr_pstrdup(p, modp->name),
+ apr_hash_set(mp_globals.module_hash, (char *)apr_pstrdup(p, modp->name),
APR_HASH_KEY_STRING, modp);
modparrot_insert_module(modp);
Modified: mod_parrot/trunk/src/nci.c
==============================================================================
--- mod_parrot/trunk/src/nci.c (original)
+++ mod_parrot/trunk/src/nci.c Sun Feb 1 08:42:05 2009
@@ -36,6 +36,7 @@
#include "../build/src/nci/server_rec.c"
extern module AP_MODULE_DECLARE_DATA parrot_module;
+extern modparrot_globals mp_globals;
/* used from PIR to pass C-style NULLs to NCI functions */
void *mpnci_null(void)
@@ -262,7 +263,7 @@
if (!ctxp) return NULL;
mpcfg = ap_get_module_config(ctxp->s->module_config, &parrot_module);
- modp = apr_hash_get(mpcfg->module_hash, name, APR_HASH_KEY_STRING);
+ modp = apr_hash_get(mp_globals.module_hash, name, APR_HASH_KEY_STRING);
if (!modp) {
return(NULL);
}
@@ -434,7 +435,7 @@
/* get current module */
cfg = ap_get_module_config(ctxp->s->module_config, &parrot_module);
- modp = ((module **)cfg->module_array->elts)[ctxp->module_index];
+ modp = ((module **)mp_globals.module_array->elts)[ctxp->module_index];
/* register the data PMC b/c it will likely go out of scope in the HLL */
if (!PMC_IS_NULL(data)) {