You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2019/04/16 23:23:38 UTC

[tcl-rivet] branch quattuor updated: transitioning towards the new server interpreters model

This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch quattuor
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git


The following commit(s) were added to refs/heads/quattuor by this push:
     new 0a1e5da  transitioning towards the new server interpreters model
0a1e5da is described below

commit 0a1e5da96721a2a13431ee43837355971c833dd5
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Wed Apr 17 01:23:24 2019 +0200

    transitioning towards the new server interpreters model
---
 ChangeLog                                |  4 ++++
 src/mod_rivet_ng/mod_rivet.h             |  2 +-
 src/mod_rivet_ng/mod_rivet_common.c      | 20 ++++++++++----------
 src/mod_rivet_ng/rivet_lazy_mpm.c        | 10 +++++-----
 src/mod_rivet_ng/rivet_worker_mpm.c      | 28 ++++++++++++++++++----------
 src/mod_rivet_ng/worker_prefork_common.c | 21 ++++++++++++---------
 6 files changed, 50 insertions(+), 35 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a7c020a..c06ea31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-16 Massimo Manghi <mx...@apache.org>
+    * src/mod_rivet_ng/: also the worker and lazy bridge transitioned to 
+    the new interpreter model
+
 2019-03-05 Massimo Manghi <mx...@apache.org>
     * src/rivet.h: Better semantics for macros RIVET_FOREACH_INTERPRETER and
     RIVET_FOREACH_VIRTUAL_HOST
diff --git a/src/mod_rivet_ng/mod_rivet.h b/src/mod_rivet_ng/mod_rivet.h
index b4c2a4c..869b88e 100644
--- a/src/mod_rivet_ng/mod_rivet.h
+++ b/src/mod_rivet_ng/mod_rivet.h
@@ -222,7 +222,7 @@ typedef struct mpm_bridge_specific mpm_bridge_specific;
 
 typedef struct _thread_worker_private {
     apr_pool_t*         pool;               /* threads private memory pool          */
-    Tcl_Channel*        channel;            /* the Tcl thread private channel       */
+    /* Tcl_Channel*     channel;   */       /* the Tcl thread private channel       */
     int                 req_cnt;            /* requests served by thread            */
     rivet_req_ctype     ctype;              /*                                      */
     request_rec*        r;                  /* current request_rec                  */
diff --git a/src/mod_rivet_ng/mod_rivet_common.c b/src/mod_rivet_ng/mod_rivet_common.c
index f2d5471..280569e 100644
--- a/src/mod_rivet_ng/mod_rivet_common.c
+++ b/src/mod_rivet_ng/mod_rivet_common.c
@@ -195,8 +195,8 @@ running_scripts* Rivet_RunningScripts ( apr_pool_t* pool,
 		char* request_handler;
 		int	  handler_size;
 
-		ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, module_globals->server, 
-                     MODNAME ": reading request handler %s",rivet_conf->request_handler);
+		//ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, module_globals->server, 
+        //             MODNAME ": reading request handler %s",rivet_conf->request_handler);
 
 		ap_assert(Rivet_ReadFile(pool,rivet_conf->request_handler,
 		                        &request_handler,&handler_size) == 0);
@@ -205,8 +205,8 @@ running_scripts* Rivet_RunningScripts ( apr_pool_t* pool,
 
     } else {
 
-		ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, module_globals->server, 
-                     MODNAME ": reading default request handler %s",module_globals->default_handler);
+		//ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, module_globals->server, 
+        //             MODNAME ": reading default request handler %s",module_globals->default_handler);
 
         scripts->request_processing = 
 				 Tcl_NewStringObj(module_globals->default_handler,
@@ -234,7 +234,7 @@ running_scripts* Rivet_RunningScripts ( apr_pool_t* pool,
  */
 void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,
 						 rivet_thread_private* private, 
-						 server_rec *s,
+						 server_rec *server,
 						 apr_pool_t *p)
 {
     Tcl_Obj*    auto_path   = NULL;
@@ -279,7 +279,7 @@ void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,
 
     if (Tcl_ListObjReplace(interp,auto_path,0,0,1,&rivet_tcl) == TCL_ERROR)
     {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, s, 
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
                      MODNAME ": error setting auto_path: %s",
                      Tcl_GetStringFromObj(auto_path,NULL));
     } else {
@@ -295,7 +295,7 @@ void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,
      * context (e.g. ::rivet::inspect) 
      */
 
-    if (private != NULL) private->running_conf = RIVET_SERVER_CONF (s->module_config);
+    if (private != NULL) private->running_conf = RIVET_SERVER_CONF (server->module_config);
 
     /* Initialize the interpreter with Rivet's Tcl commands. */
     Rivet_InitCore(interp_obj,private);
@@ -315,7 +315,7 @@ void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,
 
     if (Tcl_PkgRequire(interp,"Rivet",RIVET_INIT_VERSION,1) == NULL)
     {
-        ap_log_error (APLOG_MARK,APLOG_ERR,APR_EGENERAL,s,
+        ap_log_error (APLOG_MARK,APLOG_ERR,APR_EGENERAL,server,
                       MODNAME ": init.tcl must be installed correctly for Apache Rivet to function: %s (%s)",
                       Tcl_GetStringResult(interp),RIVET_DIR);
         exit(1);
@@ -432,7 +432,7 @@ Rivet_CreateRivetChannel(apr_pool_t* pPool, apr_threadkey_t* rivet_thread_key)
      * programmer does a "flush stdout" or the page is completed.
      */
 
-    Tcl_SetChannelBufferSize (*outchannel, TCL_MAX_CHANNEL_BUFFER_SIZE);
+    Tcl_SetChannelBufferSize (*outchannel,TCL_MAX_CHANNEL_BUFFER_SIZE);
 
     return outchannel;
 }
@@ -520,7 +520,7 @@ rivet_thread_private* Rivet_CreatePrivateData (apr_pool_t* pPool,bool create_req
     private->thread_exit    = 0;
     private->exit_status    = 0;
     private->abort_code     = NULL;
-    private->channel        = NULL;
+    //private->channel        = NULL;
     private->req            = NULL;
 
     if (create_request_obj)
diff --git a/src/mod_rivet_ng/rivet_lazy_mpm.c b/src/mod_rivet_ng/rivet_lazy_mpm.c
index c579e98..974cb45 100644
--- a/src/mod_rivet_ng/rivet_lazy_mpm.c
+++ b/src/mod_rivet_ng/rivet_lazy_mpm.c
@@ -161,7 +161,7 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
     private = Rivet_CreatePrivateData(apr_thread_pool_get(thd),true);
     ap_assert(private != NULL);
 
-    private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
+    //private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
 
     Rivet_SetupTclPanicProc();
 
@@ -172,15 +172,15 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
     private->ext = apr_pcalloc(private->pool,sizeof(mpm_bridge_specific));
     private->ext->keep_going = 1;
 
-    //private->ext->interp = Rivet_NewVHostInterp(private->pool,w->server);
+    private->ext->interp = Rivet_NewVHostInterp(private,w->server);
+    //RIVET_POKE_INTERP(private,rsc,Rivet_NewVHostInterp(private,w->server));
+    private->ext->interp->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
 
-    RIVET_POKE_INTERP(private,rsc,Rivet_NewVHostInterp(private,w->server));
-    private->ext->interp->channel = private->channel;
 
     /* The worker thread can respond to a single request at a time therefore 
        must handle and register its own Rivet channel */
 
-    Tcl_RegisterChannel(private->ext->interp->interp,*private->channel);
+    Tcl_RegisterChannel(private->ext->interp->interp,*private->ext->interp->channel);
 
     /* From the rivet_server_conf structure we determine what scripts we
      * are using to serve requests */
diff --git a/src/mod_rivet_ng/rivet_worker_mpm.c b/src/mod_rivet_ng/rivet_worker_mpm.c
index 2c26ca2..2b4e507 100644
--- a/src/mod_rivet_ng/rivet_worker_mpm.c
+++ b/src/mod_rivet_ng/rivet_worker_mpm.c
@@ -166,7 +166,8 @@ void Worker_Bridge_Shutdown (void)
     return;
 }
 
-/* -- Worker_CreateInterps 
+/* -- Worker_CreateInterps
+ *
  */
 
 static void Worker_CreateInterps (rivet_thread_private* private,rivet_thread_interp** interps)
@@ -201,8 +202,9 @@ static void Worker_CreateInterps (rivet_thread_private* private,rivet_thread_int
     }
 
 }
-/*
- * -- request_processor_ng
+
+/*-- request_processor_ng
+ *
  */
 
 static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
@@ -215,7 +217,7 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
     private = Rivet_CreatePrivateData(apr_thread_pool_get(thd),true);
     ap_assert(private != NULL);
 
-    private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
+    //private->channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
 
     Rivet_SetupTclPanicProc();
 
@@ -231,9 +233,7 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
     Worker_CreateInterps (private,private->ext->interps);
 
     /* At this stage we have to set up the private interpreters of configured 
-     * virtual hosts (if any). We assume the server_rec stored in the module
-     * globals can be used to retrieve the reference to the root interpreter
-     * configuration and to the rivet global script
+     * virtual hosts (if any). 
      */
 
     if (Rivet_SetupInterps(private) == NULL)
@@ -245,7 +245,7 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
         return NULL;
     }
 
-    /* The ng model allocates here the handler_private data */
+    /* The ng model allocates here the handler_private data structure */
 
     thread_obj = apr_pcalloc(private->pool,sizeof(handler_private));
     ap_assert(apr_thread_cond_create(&(thread_obj->cond), private->pool) == APR_SUCCESS);
@@ -256,7 +256,7 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
 
     apr_thread_mutex_unlock(module_globals->mpm->job_mutex); /* unlock job initialization stage */
 
-        /* eventually we increment the number of active threads */
+    /* Before placing the thread on the queue we increment the number of active threads */
 
     apr_atomic_inc32(module_globals->mpm->threads_count);
 
@@ -272,6 +272,10 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
             continue;
         }        
 
+        /* The request handler must change the status to init and then notify the thread
+         * to wake up and proceed with the request processing
+         */
+
         while (thread_obj->status != init)
         {
             apr_thread_cond_wait(thread_obj->cond,thread_obj->mutex);
@@ -334,6 +338,9 @@ static void* APR_THREAD_FUNC request_processor (apr_thread_t *thd, void *data)
     return NULL;
 }
 
+/* -- create_worker_thread
+ *
+ */
 
 static apr_status_t create_worker_thread (apr_thread_t** thd)
 {
@@ -755,7 +762,7 @@ apr_status_t Worker_MPM_Finalize (void* data)
  *  Results:
  *
  */
-
+#if 0
 rivet_thread_interp* MPM_MasterInterp(server_rec* s)
 {
     rivet_thread_private*   private;
@@ -768,6 +775,7 @@ rivet_thread_interp* MPM_MasterInterp(server_rec* s)
     Rivet_PerInterpInit(interp_obj, private, s, private->pool);
     return interp_obj;
 }
+#endif
 
 /*
  * -- Worker_MPM_ExitHandler
diff --git a/src/mod_rivet_ng/worker_prefork_common.c b/src/mod_rivet_ng/worker_prefork_common.c
index 85ee1f7..c4ec6bc 100644
--- a/src/mod_rivet_ng/worker_prefork_common.c
+++ b/src/mod_rivet_ng/worker_prefork_common.c
@@ -68,10 +68,13 @@ rivet_thread_private* Rivet_SetupInterps (rivet_thread_private* private)
     Tcl_Channel*            channel;
 
     root_server_conf = RIVET_SERVER_CONF (root_server->module_config);
+    channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
 
-    /* The intepreters were created by the server init script, we now create its Rivet channel */
+    /* The intepreters were created by the server init script, we now create its Rivet channel
+     * We assume the server_rec stored in the module globals can be used to retrieve the 
+     * reference to the root interpreter configuration and to the rivet global script
+     */
 
-    channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
     parentfunction = root_server_conf->rivet_child_init_script;
 
     for (s = root_server; s != NULL; s = s->next)
@@ -83,18 +86,18 @@ rivet_thread_private* Rivet_SetupInterps (rivet_thread_private* private)
         interp_obj = private->ext->interps[rsc->idx];
 
         if ((s != root_server) &&
-            (root_server_conf->separate_channels) && 
-            (root_server_conf->separate_virtual_interps))
+            root_server_conf->separate_channels && 
+            root_server_conf->separate_virtual_interps)
         {
             channel = Rivet_CreateRivetChannel(private->pool,rivet_thread_key);
-        }
-        interp_obj->channel = channel;
+        } 
 
-        Tcl_RegisterChannel(interp_obj->interp,*interp_obj->channel);
+        interp_obj->channel = channel;
+        Tcl_RegisterChannel(interp_obj->interp,*channel);
 
         /* interpreter base running scripts definition and initialization */
 
-        interp_obj->scripts = Rivet_RunningScripts (private->pool,interp_obj->scripts,rsc);
+        interp_obj->scripts = Rivet_RunningScripts(private->pool,interp_obj->scripts,rsc);
 
         private->ext->interps[rsc->idx] = interp_obj;
 
@@ -193,7 +196,7 @@ void Rivet_ProcessorCleanup (void *data)
         RivetCache_Cleanup(private,private->ext->interps[i]);
 
         if ((i > 0) && rsc->separate_channels) 
-            Rivet_ReleaseRivetChannel(private->ext->interps[i]->interp,private->channel);
+            Rivet_ReleaseRivetChannel(private->ext->interps[i]->interp,private->ext->interps[i]->channel);
 
         Tcl_DeleteInterp(private->ext->interps[i]->interp);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org