perl.cvs.mod_parrot
[Top] [All Lists]

[svn:mod_parrot] r405 - mod_parrot/trunk/src

Subject: [svn:mod_parrot] r405 - mod_parrot/trunk/src
From: jhorwitz@xxxxxxxxxxxx
Date: Sun, 27 Jul 2008 09:52:45 -0700 (PDT)
Newsgroups: perl.cvs.mod_parrot

Author: jhorwitz
Date: Sun Jul 27 09:52:45 2008
New Revision: 405

Modified:
   mod_parrot/trunk/src/context.c

Log:
add a per-process mutex for context pools under threaded MPMs


Modified: mod_parrot/trunk/src/context.c
==============================================================================
--- mod_parrot/trunk/src/context.c      (original)
+++ mod_parrot/trunk/src/context.c      Sun Jul 27 09:52:45 2008
@@ -24,6 +24,7 @@
 #include "http_connection.h"
 #include "http_main.h"
 #include "mpm.h"
+#include "apr_thread_mutex.h"
 
 #include "parrot/parrot.h"
 #include "parrot/embed.h"
@@ -32,6 +33,10 @@
 #include "mod_parrot.h"
 #include "modparrot_config.h"
 
+#ifdef MPM_IS_THREADED
+apr_thread_mutex_t *ctx_pool_mutex;
+#endif /* MPM_IS_THREADED */
+
 /* initialize pool of contexts */
 apr_array_header_t * mp_ctx_pool_init(apr_pool_t *p,
     Parrot_Interp parent_interp, int num)
@@ -50,6 +55,13 @@
         ctx->parent_interp = parent_interp;
     }
 
+#ifdef MPM_IS_THREADED
+    if (apr_thread_mutex_create(&ctx_pool_mutex, APR_THREAD_MUTEX_DEFAULT, p)
+        != APR_SUCCESS) {
+        return NULL;
+    }
+#endif /* MPM_IS_THREADED */
+        
     return ctx_pool;
 }
 
@@ -61,12 +73,19 @@
     if (!ctx_pool) return;
 
     /* pop each context off the list and destroy its interpreter */
+#ifdef MPM_IS_THREADED
+    apr_thread_mutex_lock(ctx_pool_mutex);
+#endif /* MPM_IS_THREADED */
     while ((ctxpp = apr_array_pop(ctx_pool))) {
         if ((*ctxpp)->interp) {
             modparrot_destroy_interpreter((*ctxpp)->interp);
             (*ctxpp)->interp = NULL;
         }
     }
+#ifdef MPM_IS_THREADED
+    apr_thread_mutex_unlock(ctx_pool_mutex);
+    apr_thread_mutex_destroy(ctx_pool_mutex);
+#endif /* MPM_IS_THREADED */
 
     /* apache will take care of destroying the actual context pool array */
 }
@@ -76,25 +95,28 @@
 {
 #ifdef MPM_IS_THREADED
     int i;
-#endif
+#endif /* MPM_IS_THREADED */
     modparrot_context *ctx;
 
     if (!ctx_pool) return NULL;
 #ifdef MPM_IS_THREADED
+    apr_thread_mutex_lock(ctx_pool_mutex);
     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);
+        apr_thread_mutex_destroy(ctx_pool_mutex);
         return(ctx);
     }
+    apr_thread_mutex_unlock(ctx_pool_mutex);
 
     /* XXX should wait for free context here instead of bailing */
     return (modparrot_context *)NULL;
-#else
+#else /* MPM_IS_THREADED */
     ctx = ((modparrot_context **)ctx_pool->elts)[0];
     MODPARROT_CTX_LOCK(ctx); /* no threads here, just for consistency */
     return ctx;
-#endif
+#endif /* MPM_IS_THREADED */
 }
 
 /* releases a context back into the pool of available contexts */

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:mod_parrot] r405 - mod_parrot/trunk/src, jhorwitz <=