Author: jhorwitz
Date: Mon Dec 17 10:57:56 2007
New Revision: 279
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
Log:
remove global context pool in favor of server-specific context pools
rework context API to accept a context pool argument
Modified: mod_parrot/trunk/include/mod_parrot.h
==============================================================================
--- mod_parrot/trunk/include/mod_parrot.h (original)
+++ mod_parrot/trunk/include/mod_parrot.h Mon Dec 17 10:57:56 2007
@@ -61,9 +61,9 @@
char *modparrot_backtrace(Parrot_Interp);
int modparrot_hll_handler(Parrot_Interp, char *, char *, char *, int *);
Parrot_PMC get_sub_pmc(Parrot_Interp , char *, char *);
-int mp_ctx_pool_init(apr_pool_t *, int);
-void mp_ctx_pool_destroy(void);
-modparrot_context *reserve_ctx(void);
+apr_array_header_t *mp_ctx_pool_init(apr_pool_t *, int);
+void mp_ctx_pool_destroy(apr_array_header_t *);
+modparrot_context *reserve_ctx(apr_array_header_t *);
void release_ctx(modparrot_context *);
modparrot_context *get_interp_ctx(Parrot_Interp);
void set_interp_ctx(Parrot_Interp, 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 Mon Dec 17 10:57:56 2007
@@ -28,6 +28,7 @@
struct modparrot_srv_config
{
apr_pool_t *pool;
+ apr_array_header_t *ctx_pool;
char *init_path;
int trace_flags;
char *include_path;
Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c (original)
+++ mod_parrot/trunk/src/context.c Mon Dec 17 10:57:56 2007
@@ -32,55 +32,49 @@
#include "mod_parrot.h"
#include "modparrot_config.h"
-/* pool of mod_parrot contexts */
-static apr_array_header_t *mp_ctx_pool = (apr_array_header_t *)NULL;
-
/* initialize pool of contexts */
-int mp_ctx_pool_init(apr_pool_t *p, int num)
+apr_array_header_t * mp_ctx_pool_init(apr_pool_t *p, int num)
{
int i;
+ apr_array_header_t *ctx_pool;
- if (mp_ctx_pool) return 1;
-
- if (!(mp_ctx_pool = apr_array_make(p, num, sizeof(modparrot_context)))) {
- /* XXX log error and bomb out */
- return 0;
+ if (!(ctx_pool = apr_array_make(p, num, sizeof(modparrot_context)))) {
+ return NULL;
}
for (i = 0; i < num; i++) {
- *(modparrot_context **)apr_array_push(mp_ctx_pool) =
+ *(modparrot_context **)apr_array_push(ctx_pool) =
(modparrot_context *)apr_pcalloc(p, sizeof(modparrot_context));
}
- return 1;
+ return ctx_pool;
}
/* destroy pool of contexts */
-void mp_ctx_pool_destroy(void)
+void mp_ctx_pool_destroy(apr_array_header_t *ctx_pool)
{
modparrot_context *ctx;
- if (!mp_ctx_pool) return;
+ if (!ctx_pool) return;
/* pop each context off the list and destroy its interpreter */
- while (ctx = apr_array_pop(mp_ctx_pool)) {
+ while (ctx = apr_array_pop(ctx_pool)) {
if (ctx->interp) modparrot_destroy_interpreter(ctx->interp);
}
- /* set the pool to null and let apache deal with the leftover garbage */
- mp_ctx_pool = (apr_array_header_t *)NULL;
+ /* apache will take care of destroying the actual context pool array */
}
/* finds and reserves a context for use by a handler */
-modparrot_context *reserve_ctx(void)
+modparrot_context *reserve_ctx(apr_array_header_t *ctx_pool)
{
int i;
modparrot_context *ctx;
- if (!mp_ctx_pool) return NULL;
+ if (!ctx_pool) return NULL;
#ifdef MPM_IS_THREADED
- for (i = 0; i < mp_ctx_pool->nelts; i++) {
- ctx = ((modparrot_context **)mp_ctx_pool->elts)[i];
+ for (i = 0; i < ctx_pool->nelts; i++) {
+ ctx = ((modparrot_context **)ctx_pool->elts)[i];
if (MODPARROT_CTX_ISLOCKED(ctx)) continue;
MODPARROT_CTX_LOCK(ctx);
return(ctx);
@@ -89,7 +83,7 @@
/* XXX should wait for free context here instead of bailing */
return (modparrot_context *)NULL;
#else
- ctx = ((modparrot_context **)mp_ctx_pool->elts)[0];
+ ctx = ((modparrot_context **)ctx_pool->elts)[0];
MODPARROT_CTX_LOCK(ctx); /* no threads here, just for consistency */
return ctx;
#endif
Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c (original)
+++ mod_parrot/trunk/src/mod_parrot.c Mon Dec 17 10:57:56 2007
@@ -108,7 +108,7 @@
cfg = ap_get_module_config(s->module_config, &parrot_module);
- if ((ctxp = reserve_ctx())) {
+ if ((ctxp = reserve_ctx(cfg->ctx_pool))) {
if (!ctxp->interp) {
if (!(interp = modparrot_init(ctxp, s))) {
MPLOG_ERROR(s,
@@ -825,14 +825,6 @@
return handler_status;
}
-static apr_status_t modparrot_cleanup(void *data)
-{
- server_rec *s = (server_rec *)data;
-
- mp_ctx_pool_destroy();
- return APR_SUCCESS;
-}
-
static int modparrot_open_logs_handler(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
@@ -841,16 +833,6 @@
int handler_status;
char *sub, *hll;
- /* initialize context pool */
- if (!mp_ctx_pool_init(pconf, 2)) {
- MPLOG_ERROR(s, "context pool creation failed");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
-
- /* destroy context pool on cleanup */
- apr_pool_cleanup_register(pconf, s, modparrot_cleanup,
- apr_pool_cleanup_null);
-
/* get apache configs */
cfg = ap_get_module_config(s->module_config, &parrot_module);
Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c (original)
+++ mod_parrot/trunk/src/modparrot_config.c Mon Dec 17 10:57:56 2007
@@ -35,6 +35,18 @@
extern module AP_MODULE_DECLARE_DATA parrot_module;
+static apr_status_t modparrot_cleanup(void *data)
+{
+ modparrot_srv_config *cfg;
+ apr_array_header_t *ctx_pool;
+ server_rec *s = (server_rec *)data;
+
+ cfg = ap_get_module_config(s->module_config, &parrot_module);
+ mp_ctx_pool_destroy(cfg->ctx_pool);
+
+ return APR_SUCCESS;
+}
+
void *create_modparrot_srv_config(apr_pool_t *p, server_rec *s)
{
modparrot_srv_config *cfg;
@@ -48,6 +60,15 @@
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);
+
/* set default HLL to PIR */
apr_table_set(cfg->handler_map, MODPARROT_MAGIC, MODPARROT_DEFAULT_HLL);
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.