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 2015/03/28 10:56:04 UTC
svn commit: r1669737 - in /tcl/rivet/trunk: ChangeLog
src/mod_rivet/mod_rivet.c src/mod_rivet/mod_rivet.h
src/mod_rivet/mod_rivet_common.c src/mod_rivet/mod_rivet_common.h
src/mod_rivet/rivet_prefork_mpm.c src/mod_rivet/rivet_worker_mpm.c
Author: mxmanghi
Date: Sat Mar 28 09:56:03 2015
New Revision: 1669737
URL: http://svn.apache.org/r1669737
Log:
* src/mod_rivet/mod_rivet.[c|h]: moved Tcl panic procedure data from
mod_rivet_globals to rivet_thread_private
* src/mod_rivet/mod_rivet_common.[c|h]: new procedure Rivet_SetupTclPanicProc
and Rivet_PanicProc fixed to handle thread private data to get valid
and thread safe information about the module status. New procedure
Rivet_CreatePrivateData should provide a common method for all bridges
to create thread private data
* src/mod_rivet/rivet_[prefork|worker]_mpm.c: exploiting
Rivet_CreatePrivateData and Rivet_SetupTclPanicProc makes code
more localized, removes redundancy and improves readability
Modified:
tcl/rivet/trunk/ChangeLog
tcl/rivet/trunk/src/mod_rivet/mod_rivet.c
tcl/rivet/trunk/src/mod_rivet/mod_rivet.h
tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.c
tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.h
tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c
tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c
Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Sat Mar 28 09:56:03 2015
@@ -1,4 +1,16 @@
2015-03-28 Massimo Manghi <mx...@apache.org>
+ * src/mod_rivet/mod_rivet.[c|h]: moved Tcl panic procedure data from
+ mod_rivet_globals to rivet_thread_private
+ * src/mod_rivet/mod_rivet_common.[c|h]: new procedure Rivet_SetupTclPanicProc
+ and Rivet_PanicProc fixed to handle thread private data to get valid
+ and thread safe information about the module status. New procedure
+ Rivet_CreatePrivateData should provide a common method for all bridges
+ to create thread private data
+ * src/mod_rivet/rivet_[prefork|worker]_mpm.c: exploiting
+ Rivet_CreatePrivateData and Rivet_SetupTclPanicProc makes code
+ more localized, removes redundancy and improves readability
+
+2015-03-18 Massimo Manghi <mx...@apache.org>
* INSTALL: update installation and configuration examples
2015-03-11 Massimo Manghi <mx...@apache.org>
Modified: tcl/rivet/trunk/src/mod_rivet/mod_rivet.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/mod_rivet.c?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet.c Sat Mar 28 09:56:03 2015
@@ -60,7 +60,6 @@
#include "apache_config.h"
mod_rivet_globals* module_globals;
-//rivet_server_conf rsc;
rivet_interp_globals interp_globals;
extern Tcl_ChannelType RivetChan;
@@ -515,7 +514,7 @@ Rivet_SendContent(rivet_thread_private *
gets called in general it won't have this pointer which has to be
thread private */
- module_globals->rivet_panic_request_rec = private->r;
+ private->rivet_panic_request_rec = private->r;
// rsc = Rivet_GetConf(r);
@@ -1501,16 +1500,12 @@ Rivet_ServerInit (apr_pool_t *pPool, apr
apr_atomic_set32(module_globals->running_threads_count,0);
module_globals->workers = NULL;
- module_globals->rivet_panic_pool = pPool;
- module_globals->rivet_panic_server_rec = server;
- module_globals->rivet_panic_request_rec = NULL;
module_globals->vhosts_count = 0;
module_globals->server_shutdown = 0;
module_globals->exiting = NULL;
module_globals->mpm_max_threads = 0;
module_globals->mpm_min_spare_threads = 0;
module_globals->mpm_max_spare_threads = 0;
- //module_globals->num_load_samples = 0;
/* Another crucial point: we are storing here in the globals a reference to the
* root server_rec object from which threads are supposed to derive
Modified: tcl/rivet/trunk/src/mod_rivet/mod_rivet.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/mod_rivet.h?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet.h Sat Mar 28 09:56:03 2015
@@ -106,8 +106,7 @@ typedef struct _rivet_server_conf {
/* This flag is used with the above directives. If any of them have changed, it gets set. */
- unsigned int user_scripts_status;
- //int user_scripts_updated;
+ unsigned int user_scripts_status;
int default_cache_size;
int upload_max;
@@ -124,16 +123,17 @@ typedef struct _rivet_server_conf {
char* path; /* copy of the path field of a cmd_parms structure:
should enable us to tell if a conf record comes from a
Directory section */
- //int user_conf;
+ //int user_conf;
- //Tcl_Interp *server_interp; /* per server Tcl interpreter */
- //int* cache_size;
- //int* cache_free;
- //char** objCacheList; /* Array of cached objects (for priority handling) */
- //Tcl_HashTable* objCache; /* Objects cache - the key is the script name */
+ //Tcl_Interp *server_interp; /* per server Tcl interpreter */
+ //int* cache_size;
+ //int* cache_free;
+ //char** objCacheList; /* Array of cached objects (for priority handling) */
+ //Tcl_HashTable* objCache; /* Objects cache - the key is the script name */
/* this one must go, we keep just to avoid to duplicate the config handling function just
to avoid to poke stuff into this field */
+
//Tcl_Channel* outchannel; /* stuff for buffering output */
@@ -205,10 +205,6 @@ typedef struct _mod_rivet_globals {
vhost_interp* (*mpm_master_interp)(void);
int (*mpm_exit_handler)(int);
- request_rec* rivet_panic_request_rec;
- apr_pool_t* rivet_panic_pool;
- server_rec* rivet_panic_server_rec;
-
int mpm_max_threads;
int mpm_min_spare_threads;
int mpm_max_spare_threads;
@@ -240,6 +236,10 @@ typedef struct _thread_worker_private {
running_scripts* running; /* (per request) running conf scripts */
int thread_exit; /* Flag signalling thread_exit call */
+ request_rec* rivet_panic_request_rec;
+ apr_pool_t* rivet_panic_pool;
+ server_rec* rivet_panic_server_rec;
+
} rivet_thread_private;
/* eventually we will transfer 'global' variables in here and 'de-globalize' them */
Modified: tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.c?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.c Sat Mar 28 09:56:03 2015
@@ -37,6 +37,7 @@
#include "apache_config.h"
extern mod_rivet_globals* module_globals;
+extern apr_threadkey_t* rivet_thread_key;
/*
*-----------------------------------------------------------------------------
@@ -82,6 +83,88 @@ Rivet_CreateRivetChannel(apr_pool_t* pPo
return outchannel;
}
+/*-----------------------------------------------------------------------------
+ *
+ * -- Rivet_CreatePrivateData
+ *
+ * Creates a thread private data object
+ *
+ * Arguments:
+ *
+ * - apr_threadkey_t* rivet_thread_key
+ *
+ * Returned value:
+ *
+ * - rivet_thread_private* private data object
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+rivet_thread_private* Rivet_CreatePrivateData (void)
+{
+ rivet_thread_private* private;
+
+ if (apr_threadkey_private_get ((void **)&private,rivet_thread_key) != APR_SUCCESS)
+ {
+ return NULL;
+ }
+
+ apr_thread_mutex_lock(module_globals->pool_mutex);
+ private = apr_palloc (module_globals->pool,sizeof(*private));
+ apr_thread_mutex_unlock(module_globals->pool_mutex);
+
+ private->req_cnt = 0;
+ private->keep_going = 1;
+ private->r = NULL;
+ private->req = NULL;
+ private->request_init = Tcl_NewStringObj("::Rivet::initialize_request\n", -1);
+ private->request_cleanup = Tcl_NewStringObj("::Rivet::cleanup_request\n", -1);
+ Tcl_IncrRefCount(private->request_init);
+ Tcl_IncrRefCount(private->request_cleanup);
+
+ if (apr_pool_create (&private->pool, NULL) != APR_SUCCESS)
+ {
+ ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, module_globals->server,
+ MODNAME ": could not create thread private pool");
+ return NULL;
+ }
+
+ /* We allocate the array for the interpreters database.
+ * Data referenced in this database must be freed by the thread before exit
+ */
+
+ private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
+ private->interps = apr_pcalloc(private->pool,module_globals->vhosts_count*sizeof(vhost_interp));
+ apr_threadkey_private_set (private,rivet_thread_key);
+
+ return private;
+}
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * Rivet_SetupTclPanicProc --
+ *
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+rivet_thread_private*
+Rivet_SetupTclPanicProc (void)
+{
+ rivet_thread_private* private;
+
+ ap_assert (apr_threadkey_private_get ((void **)&private,rivet_thread_key) == APR_SUCCESS);
+
+ private->rivet_panic_pool = private->pool;
+ private->rivet_panic_server_rec = module_globals->server;
+ private->rivet_panic_request_rec = NULL;
+
+ return private;
+}
+
+
+
/*
*-----------------------------------------------------------------------------
*
@@ -101,22 +184,25 @@ Rivet_CreateRivetChannel(apr_pool_t* pPo
*/
void Rivet_Panic TCL_VARARGS_DEF(CONST char *, arg1)
{
- va_list argList;
- char *buf;
- char *format;
+ va_list argList;
+ char* buf;
+ char* format;
+ rivet_thread_private* private;
+
+ ap_assert (apr_threadkey_private_get ((void **)&private,rivet_thread_key) == APR_SUCCESS);
format = (char *) TCL_VARARGS_START(char *,arg1,argList);
- buf = (char *) apr_pvsprintf(module_globals->rivet_panic_pool, format, argList);
+ buf = (char *) apr_pvsprintf(private->rivet_panic_pool, format, argList);
- if (module_globals->rivet_panic_request_rec != NULL) {
+ if (private->rivet_panic_request_rec != NULL) {
ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL,
- module_globals->rivet_panic_server_rec,
+ private->rivet_panic_server_rec,
MODNAME ": Critical error in request: %s",
- module_globals->rivet_panic_request_rec->unparsed_uri);
+ private->rivet_panic_request_rec->unparsed_uri);
}
ap_log_error(APLOG_MARK, APLOG_CRIT, APR_EGENERAL,
- module_globals->rivet_panic_server_rec, "%s", buf);
+ private->rivet_panic_server_rec, "%s", buf);
abort();
}
Modified: tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.h
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.h?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.h (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet_common.h Sat Mar 28 09:56:03 2015
@@ -27,4 +27,6 @@ EXTERN void Rivet_CleanupRequest(request
EXTERN void Rivet_InitServerVariables(Tcl_Interp *interp, apr_pool_t *pool);
EXTERN void Rivet_Panic TCL_VARARGS_DEF(CONST char *, arg1);
EXTERN Tcl_Channel* Rivet_CreateRivetChannel(apr_pool_t* pPool, apr_threadkey_t* rivet_thread_key);
+EXTERN rivet_thread_private* Rivet_CreatePrivateData (void);
+EXTERN rivet_thread_private* Rivet_SetupTclPanicProc (void);
#endif
Modified: tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c Sat Mar 28 09:56:03 2015
@@ -108,74 +108,29 @@ int Rivet_MPM_ServerInit (apr_pool_t *pP
void Rivet_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
{
rivet_thread_private* private;
- //Tcl_Channel* outchannel;
- /* This is the only execution thread in this process so we create
+ /*
+ * This is the only execution thread in this process so we create
* the Tcl thread private data here
*/
- if (apr_threadkey_private_get ((void **)&private,rivet_thread_key) != APR_SUCCESS)
- {
- exit(1);
- }
- else
- {
+ ap_assert (apr_threadkey_private_get ((void **)&private,rivet_thread_key) == APR_SUCCESS);
+ if (private == NULL)
+ {
+ private = Rivet_CreatePrivateData();
if (private == NULL)
{
- apr_thread_mutex_lock(module_globals->pool_mutex);
- private = apr_palloc (module_globals->pool,sizeof(rivet_thread_private));
- apr_thread_mutex_unlock(module_globals->pool_mutex);
-
- if (apr_pool_create(&private->pool, NULL) != APR_SUCCESS)
- {
- ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server,
- MODNAME ": could not create child thread private pool");
- exit(1);
- }
-
- private->req_cnt = 0;
- private->keep_going = 1;
- private->r = NULL;
- private->req = NULL;
- private->request_init = Tcl_NewStringObj("::Rivet::initialize_request\n", -1);
- private->request_cleanup = Tcl_NewStringObj("::Rivet::cleanup_request\n", -1);
- Tcl_IncrRefCount(private->request_init);
- Tcl_IncrRefCount(private->request_cleanup);
-
- //private->channel = apr_pcalloc(private->pool,sizeof(Tcl_Channel));
- //private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
- private->interps = apr_pcalloc(private->pool,module_globals->vhosts_count*sizeof(vhost_interp));
-
- /*
- * We also create thread/child global output channel.
- */
+ /* TODO: we have to log something here */
- private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
-
- apr_threadkey_private_set (private,rivet_thread_key);
+ exit(1);
}
-
+ Rivet_SetupTclPanicProc ();
}
- //outchannel = private->channel;
- //*outchannel = Tcl_CreateChannel(&RivetChan, "apacheout", rivet_thread_key, TCL_WRITABLE);
-
- /* The channel we have just created replaces Tcl's stdout */
-
- //Tcl_SetStdChannel (*outchannel, TCL_STDOUT);
-
- /* Set the output buffer size to the largest allowed value, so that we
- * won't send any result packets to the browser unless the Rivet
- * programmer does a "flush stdout" or the page is completed.
- */
-
- //Tcl_SetChannelBufferSize (*outchannel, TCL_MAX_CHANNEL_BUFFER_SIZE);
-
-
- /*
- * We proceed creating the vhost interpreters database
- */
+ /*
+ * We proceed creating the vhost interpreters database
+ */
if (Rivet_VirtualHostsInterps (private) == NULL)
{
Modified: tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c?rev=1669737&r1=1669736&r2=1669737&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c Sat Mar 28 09:56:03 2015
@@ -104,51 +104,23 @@ static void* APR_THREAD_FUNC request_pro
{
rivet_thread_private* private;
//Tcl_Channel* outchannel; /* stuff for buffering output */
- server_rec* server;
+ //server_rec* server;
apr_thread_mutex_lock(module_globals->job_mutex);
- server = module_globals->server;
+ //server = module_globals->server;
- if (apr_threadkey_private_get ((void **)&private,rivet_thread_key) != APR_SUCCESS)
- {
- return NULL;
- }
- else
+ ap_assert (apr_threadkey_private_get ((void **)&private,rivet_thread_key) == APR_SUCCESS);
+ if (private == NULL)
{
+ private = Rivet_CreatePrivateData();
- if (private == NULL)
+ if (private == NULL)
{
- apr_thread_mutex_lock(module_globals->pool_mutex);
- private = apr_palloc (module_globals->pool,sizeof(*private));
- apr_thread_mutex_unlock(module_globals->pool_mutex);
-
- private->req_cnt = 0;
- private->keep_going = 1;
- private->r = NULL;
- private->req = NULL;
- private->request_init = Tcl_NewStringObj("::Rivet::initialize_request\n", -1);
- private->request_cleanup = Tcl_NewStringObj("::Rivet::cleanup_request\n", -1);
- Tcl_IncrRefCount(private->request_init);
- Tcl_IncrRefCount(private->request_cleanup);
-
- if (apr_pool_create(&private->pool, NULL) != APR_SUCCESS)
- {
- ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server,
- MODNAME ": could not create thread private pool");
- apr_thread_exit(thd,APR_SUCCESS);
- return NULL;
- }
-
- /* We allocate the array for the interpreters database.
- * Data referenced in this database must be freed by the thread before exit
- */
-
- //private->channel = apr_pcalloc(private->pool,sizeof(Tcl_Channel));
- private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
- private->interps = apr_pcalloc(private->pool,module_globals->vhosts_count*sizeof(vhost_interp));
- apr_threadkey_private_set (private,rivet_thread_key);
-
+ /* TODO: we have to log something here */
+ apr_thread_exit(thd,APR_SUCCESS);
}
+ Rivet_SetupTclPanicProc ();
+
}
/* So far nothing differs much with what we did for the prefork bridge */
---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org