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/12/14 01:50:43 UTC

svn commit: r1719851 - in /tcl/rivet/trunk: ChangeLog doc/xml/asciiglyphs.xml src/mod_rivet/mod_rivet.c src/mod_rivet/rivet_prefork_mpm.c src/mod_rivet/rivet_worker_mpm.c

Author: mxmanghi
Date: Mon Dec 14 00:50:43 2015
New Revision: 1719851

URL: http://svn.apache.org/viewvc?rev=1719851&view=rev
Log:
    * src/mod_rivet/rivet_worker_mpm.c: changed in order to have a better handling
    of ::rivet::exit (the call to exit( ) is now carried out from within the
    supervising thread
    * src/mod_rivet/rivet_prefork_mpm.c: Adding exit command handler
    * src/mod_rivet/mod_rivet.c: new central Rivet_Finalize method that calls
    any bridge module finalization. The function deletes the thread key to
    access private data


Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/doc/xml/asciiglyphs.xml
    tcl/rivet/trunk/src/mod_rivet/mod_rivet.c
    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=1719851&r1=1719850&r2=1719851&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Mon Dec 14 00:50:43 2015
@@ -1,3 +1,12 @@
+2015-12-13 Massimo Manghi <mx...@apache.org>
+    * src/mod_rivet/rivet_worker_mpm.c: changed in order to have a better handling
+    of ::rivet::exit (the call to exit( ) is now carried out from within the
+    supervising thread
+    * src/mod_rivet/rivet_prefork_mpm.c: Adding exit command handler
+    * src/mod_rivet/mod_rivet.c: new central Rivet_Finalize method that calls
+    any bridge module finalization. The function deletes the thread key to
+    access private data
+
 2015-12-08 Massimo Manghi <mx...@apache.org>
     * doc/xml/commands.xml,asciiglyphs.tcl: adding documentation for ::rivet::try
     and AsciiGlyphs

Modified: tcl/rivet/trunk/doc/xml/asciiglyphs.xml
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/doc/xml/asciiglyphs.xml?rev=1719851&r1=1719850&r2=1719851&view=diff
==============================================================================
--- tcl/rivet/trunk/doc/xml/asciiglyphs.xml (original)
+++ tcl/rivet/trunk/doc/xml/asciiglyphs.xml Mon Dec 14 00:50:43 2015
@@ -12,8 +12,31 @@
 				The string to be represented has to be made of pure 7-bit ASCII characters.
 				The package also runs standalone outside of mod_rivet
         </para>
-
-			<programlisting>package require AsciiGlyphs
+     </section>
+    <refentry id="toglyphs">
+	        <refnamediv>
+	            <refname>toGlyphs</refname>
+	            <refpurpose>
+	            	print large ASCII glyphs
+	            </refpurpose>
+	        </refnamediv>
+	        <refsynopsisdiv>
+	            <cmdsynopsis>
+	                <command>::AsciiGlyphs toGlyphs</command>
+	                <arg choice="plain">string</arg>
+	            </cmdsynopsis>
+	        </refsynopsisdiv>
+	        <refsect1>
+            <title>Description</title>
+            <para>
+            	prints the ASCII glyphs corresponding to the characters forming
+    		        	the argument <arg choice="plain">string</arg>
+            </para>
+           </refsect1>
+		  </refentry>
+		  <section>
+		  	<title>Example</title>
+		  		<programlisting>package require AsciiGlyphs
 ::AsciiGlyphs toGlyphs "Date: 07-12-2015"
  _____              _____   ______          ___   ______         __  ___          ___    ___   __  _____ 
 |  __ \     /\     |_   _| |  ____|  _     / _ \ |____  |       /_ ||__ \        |__ \  / _ \ /_ || ____|

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=1719851&r1=1719850&r2=1719851&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet.c Mon Dec 14 00:50:43 2015
@@ -433,11 +433,12 @@ rivet_thread_private* Rivet_VirtualHosts
 }
 
 
-/* ----------------------------------------------------------------------------
+/*
  * -- Rivet_SendContent
  *
- *   Set things up to execute a file, then execute 
- *-----------------------------------------------------------------------------
+ *   Set things up to execute a Tcl script or parse a rvt template, prepare
+ *   the environment then execute it as a pure Tcl script
+ *
  */
 
 #define USE_APACHE_RSC
@@ -698,7 +699,7 @@ sendcleanup:
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, private->r, 
                                   "process terminating with code %d",private->exit_status);
         RIVET_MPM_BRIDGE_CALL(mpm_exit_handler,private->exit_status);
-        Tcl_Exit(private->exit_status);
+        //Tcl_Exit(private->exit_status);
     }
 
     /* We now reset the status to prepare the child process for another request */
@@ -1229,7 +1230,7 @@ Rivet_CreateTclInterp (server_rec* s)
  *
  *-----------------------------------------------------------------------------
  */
-void  Rivet_PerInterpInit(rivet_thread_interp* interp_obj,rivet_thread_private* private, server_rec *s, apr_pool_t *p)
+void Rivet_PerInterpInit(rivet_thread_interp* interp_obj,rivet_thread_private* private, server_rec *s, apr_pool_t *p)
 {
     rivet_interp_globals*   globals     = NULL;
     Tcl_Obj*                auto_path   = NULL;
@@ -1529,6 +1530,20 @@ Rivet_ServerInit (apr_pool_t *pPool, apr
     return OK;
 }
 
+/*
+ * -- Rivet_Finalize
+ *
+ */
+
+apr_status_t Rivet_Finalize(void* data)
+{
+
+    RIVET_MPM_BRIDGE_CALL(mpm_finalize,data);
+    apr_threadkey_private_delete (rivet_thread_key);
+
+    return OK;
+}
+
 static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
 {
     int                 idx;
@@ -1584,20 +1599,10 @@ static void Rivet_ChildInit (apr_pool_t
 
     RIVET_MPM_BRIDGE_CALL(mpm_child_init,pChild,server);
 
-    if (RIVET_MPM_BRIDGE_FUNCTION(mpm_finalize) == NULL)
-    {
-        apr_pool_cleanup_register (pChild, server,
-                                    apr_pool_cleanup_null,
-                                    apr_pool_cleanup_null);
-    }
-    else
-    {
-        apr_pool_cleanup_register (pChild, server,
-                                    RIVET_MPM_BRIDGE_FUNCTION(mpm_finalize),
-                                    RIVET_MPM_BRIDGE_FUNCTION(mpm_finalize));
-    }
+    apr_pool_cleanup_register (pChild,server,Rivet_Finalize,Rivet_Finalize);
 }
 
+
 static int Rivet_Handler (request_rec *r)    
 {
     rivet_req_ctype ctype = Rivet_CheckType(r);  

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=1719851&r1=1719850&r2=1719851&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c Mon Dec 14 00:50:43 2015
@@ -51,7 +51,6 @@ apr_status_t Prefork_MPM_Finalize (void*
     // No, we don't clean up anymore as we are just shutting this process down
     // Rivet_ProcessorCleanup(private);
 
-    apr_threadkey_private_delete (rivet_thread_key);
     return OK;
 }
 
@@ -141,12 +140,33 @@ rivet_thread_interp* Prefork_MPM_MasterI
     return module_globals->server_interp;
 }
 
+/*
+ * -- Prefork_MPM_ExitHandler
+ *
+ *  Just calling Tcl_Exit  
+ *
+ *  Arguments:
+ *      int code
+ *
+ * Side Effects:
+ *
+ *  the thread running the Tcl script will exit 
+ */
+
+int Prefork_MPM_ExitHandler(int code)
+{
+    Tcl_Exit(code);
+
+    /* it will never get here */
+    return TCL_OK;
+}
+
 RIVET_MPM_BRIDGE {
     NULL,
     Prefork_MPM_ChildInit,
     Prefork_MPM_Request,
     Prefork_MPM_Finalize,
     Prefork_MPM_MasterInterp,
-    NULL
+    Prefork_MPM_ExitHandler
 };
 

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=1719851&r1=1719850&r2=1719851&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c Mon Dec 14 00:50:43 2015
@@ -66,6 +66,8 @@ typedef struct mpm_bridge_status {
     apr_uint32_t*       running_threads_count;
     apr_queue_t*        queue;                  /* jobs queue               */
     void**              workers;                /* thread pool ids          */
+    int                 exit_command;
+    int                 exit_command_status;
 
     int                 max_threads;
     int                 min_spare_threads;
@@ -138,11 +140,10 @@ void Worker_Bridge_Shutdown (void)
     waits = 5;
     count = (int) apr_atomic_read32(module_globals->mpm->threads_count);
     for (i = 0; i < count; i++) { apr_queue_push(module_globals->mpm->queue,job); }
-    apr_sleep(500000);
+    apr_sleep(1000000);
 
     do 
     {
-
         count = (int) apr_atomic_read32(module_globals->mpm->threads_count);
 
         /* Actually, when Rivet exit command implementation shuts the bridge down
@@ -154,10 +155,18 @@ void Worker_Bridge_Shutdown (void)
 
         ap_log_error(APLOG_MARK, APLOG_ERR, APR_SUCCESS, module_globals->server, 
             "Sending %d more stop signals to threads",count);
-        apr_sleep(1000000);
+        for (i = 0; i < count; i++) { apr_queue_push(module_globals->mpm->queue,job); }
+
+        apr_sleep(500000);
 
     } while (waits-- > 0);
 
+    count = (int) apr_atomic_read32(module_globals->mpm->threads_count);
+    if (count > 0) 
+    {
+        ap_log_error(APLOG_MARK,APLOG_ERR,APR_EGENERAL,module_globals->server, 
+            "%d threads are still running after 5 attempts. Child process exits anyway",count);
+    }
     return;
 }
 
@@ -407,15 +416,10 @@ static void* APR_THREAD_FUNC threaded_br
 
     Worker_Bridge_Shutdown();
     
+    if (module_globals->mpm->exit_command)
     {
-        int count = (int) apr_atomic_read32(mpm->threads_count);
-        if (count > 0) 
-        {
-
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, module_globals->server, 
-                "%d threads are still running after 5 attempts. Child process exits anyway",count);
-
-        }
+        ap_log_error(APLOG_MARK,APLOG_DEBUG,APR_SUCCESS,module_globals->server,"Orderly child process exits.");
+        exit(module_globals->mpm->exit_command_status);
     }
 
     ap_log_error(APLOG_MARK,APLOG_DEBUG,APR_SUCCESS,module_globals->server,"Worker bridge supervisor shuts down");
@@ -456,6 +460,7 @@ void Worker_MPM_ChildInit (apr_pool_t* p
     module_globals->mpm->max_spare_threads  = 0;
     module_globals->mpm->workers            = NULL;
     module_globals->mpm->server_shutdown    = 0;
+    module_globals->mpm->exit_command       = 0;
 
     /* We keep some atomic counters that could provide basic data for a workload balancer */
 
@@ -633,10 +638,10 @@ int Worker_MPM_Request (request_rec* r,r
          * wait on the condition variable associated to the request_private structure */
 
         apr_thread_mutex_lock(request_private->mutex);
-        while (request_private->status != done)
+        do 
         {
             apr_thread_cond_wait(request_private->cond,request_private->mutex);
-        }
+        } while (request_private->status == init); 
         apr_thread_mutex_unlock(request_private->mutex);
     }
     else
@@ -671,15 +676,17 @@ apr_status_t Worker_MPM_Finalize (void*
     apr_thread_cond_signal(module_globals->mpm->job_cond);
     apr_thread_mutex_unlock(module_globals->mpm->job_mutex);
 
-    rv = apr_thread_join (&thread_status,module_globals->mpm->supervisor);
-    if (rv != APR_SUCCESS)
+    if (!module_globals->mpm->exit_command)
     {
-        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
-                     MODNAME ": Error joining supervisor thread");
+        rv = apr_thread_join (&thread_status,module_globals->mpm->supervisor);
+        if (rv != APR_SUCCESS)
+        {
+            ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                         MODNAME ": Error joining supervisor thread");
+        }
     }
 
-    apr_threadkey_private_delete (rivet_thread_key);
-    apr_threadkey_private_delete (handler_thread_key);
+    // apr_threadkey_private_delete (handler_thread_key);
     return OK;
 }
 
@@ -734,6 +741,9 @@ int Worker_MPM_ExitHandler(int code)
 
     private->keep_going = 0;
 
+    module_globals->mpm->exit_command = 1;
+    module_globals->mpm->exit_command_status = code;
+
     /* We now tell the whole process to shutdown */
  
     Worker_MPM_Finalize (private->r->server);



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