You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2014/08/14 23:54:00 UTC
svn commit: r1618071 - in /tcl/rivet/trunk/src/experimental: mod_rivet.c
mod_rivet.h rivet_worker_mpm.c
Author: mxmanghi
Date: Thu Aug 14 21:54:00 2014
New Revision: 1618071
URL: http://svn.apache.org/r1618071
Log:
adding lock protecting Tcl script evaluation
Modified:
tcl/rivet/trunk/src/experimental/mod_rivet.c
tcl/rivet/trunk/src/experimental/mod_rivet.h
tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c
Modified: tcl/rivet/trunk/src/experimental/mod_rivet.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/mod_rivet.c?rev=1618071&r1=1618070&r2=1618071&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/experimental/mod_rivet.c Thu Aug 14 21:54:00 2014
@@ -71,6 +71,8 @@ void Rivet_PerInterpInit(Tcl_Interp* in
#define ERRORBUF_SZ 256
+TCL_DECLARE_MUTEX(sendMutex);
+
vhost_interp* Rivet_NewVHostInterp(apr_pool_t* pool)
{
extern int ap_max_requests_per_child;
@@ -423,6 +425,8 @@ Rivet_SendContent(rivet_thread_private *
Tcl_IncrRefCount(request_init);
}
+
+ apr_thread_mutex_lock(module_globals->req_mutex);
if (Tcl_EvalObjEx(interp, request_init, 0) == TCL_ERROR)
{
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server,
@@ -430,8 +434,10 @@ Rivet_SendContent(rivet_thread_private *
Tcl_GetStringResult(interp));
retval = HTTP_INTERNAL_SERVER_ERROR;
+ apr_thread_mutex_unlock(module_globals->req_mutex);
goto sendcleanup;
}
+ apr_thread_mutex_unlock(module_globals->req_mutex);
/* Apache Request stuff */
@@ -491,6 +497,7 @@ Rivet_SendContent(rivet_thread_private *
}
}
+ apr_thread_mutex_lock(module_globals->req_mutex);
if (Rivet_ParseExecFile(private, r->filename, 1) != TCL_OK)
{
ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r->server,
@@ -509,6 +516,7 @@ Rivet_SendContent(rivet_thread_private *
MODNAME ": Error evaluating cleanup request: %s",
Tcl_GetVar(interp, "errorInfo", 0));
}
+ apr_thread_mutex_unlock(module_globals->req_mutex);
/* Reset globals */
Rivet_CleanupRequest( r );
@@ -1238,6 +1246,8 @@ static void Rivet_ChildInit (apr_pool_t
rivet_server_conf* root_server_conf;
server_rec* s;
+ apr_thread_mutex_create(&module_globals->req_mutex, APR_THREAD_MUTEX_UNNESTED, pChild);
+
/* This code is run once per child process. In a threaded Tcl builds the forking
* of a child process most likely has not preserved the thread where the Tcl
* notifier runs. The Notifier should have been restarted by one the
Modified: tcl/rivet/trunk/src/experimental/mod_rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/mod_rivet.h?rev=1618071&r1=1618070&r2=1618071&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/experimental/mod_rivet.h Thu Aug 14 21:54:00 2014
@@ -158,7 +158,7 @@ typedef struct _mod_rivet_globals {
apr_thread_t* supervisor;
int server_shutdown;
int vhosts_count;
- vhost_interp* server_interp; /* server init and prefork MPM master interpreter */
+ vhost_interp* server_interp; /* server and prefork MPM interpreter */
apr_thread_cond_t* job_cond;
apr_thread_mutex_t* job_mutex;
@@ -192,6 +192,7 @@ typedef struct _mod_rivet_globals {
double average_working_threads;
*/
+ apr_thread_mutex_t* req_mutex;
} mod_rivet_globals;
#define BRIDGE_SUPERVISOR_WAIT 1000000
Modified: tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c?rev=1618071&r1=1618070&r2=1618071&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c (original)
+++ tcl/rivet/trunk/src/experimental/rivet_worker_mpm.c Thu Aug 14 21:54:00 2014
@@ -21,6 +21,7 @@
/* $Id: */
+#include <httpd.h>
#include <math.h>
#include <tcl.h>
#include <ap_mpm.h>
@@ -193,9 +194,9 @@ static void* APR_THREAD_FUNC request_pro
private->r = request_obj->r;
private->req = request_obj->req;
- //request_obj->code = RivetContent (private);
-
+ //apr_thread_mutex_lock(module_globals->req_mutex);
request_obj->code = Rivet_SendContent(private);
+ //apr_thread_mutex_unlock(module_globals->req_mutex);
apr_thread_mutex_lock(request_obj->mutex);
request_obj->status = done;
@@ -486,23 +487,22 @@ int Rivet_MPM_Request (request_rec* r)
request_private->status = init;
apr_threadkey_private_set (request_private,handler_thread_key);
- do
+ rv = apr_queue_push(module_globals->queue,request_private);
+ if (rv == APR_SUCCESS)
{
-
- rv = apr_queue_push(module_globals->queue,request_private);
- if (rv != APR_SUCCESS)
+ apr_thread_mutex_lock(request_private->mutex);
+ while (request_private->status != done)
{
- apr_sleep(100000);
+ apr_thread_cond_wait(request_private->cond,request_private->mutex);
}
+ apr_thread_mutex_unlock(request_private->mutex);
- } while (rv != APR_SUCCESS);
-
- apr_thread_mutex_lock(request_private->mutex);
- while (request_private->status != done)
+ }
+ else
{
- apr_thread_cond_wait(request_private->cond,request_private->mutex);
+ request_private->code = HTTP_INTERNAL_SERVER_ERROR;
+ // apr_sleep(100000);
}
- apr_thread_mutex_unlock(request_private->mutex);
return request_private->code;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org