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/08/18 22:15:43 UTC

svn commit: r1696494 - in /tcl/rivet/trunk: ChangeLog src/mod_rivet/mod_rivet.c src/mod_rivet/mod_rivet.h src/mod_rivet/rivetCore.c src/mod_rivet/rivet_prefork_mpm.c src/mod_rivet/rivet_worker_mpm.c

Author: mxmanghi
Date: Tue Aug 18 20:15:43 2015
New Revision: 1696494

URL: http://svn.apache.org/r1696494
Log:
    * src/mod_rivet/mod_rivet.[c|h]: now calling MPM through
    a bridge_jump_table structure with all the functions exported
    by a bridge implementation. Created default exit handler
    so that only if a special exit handler is needed it has
    to be defined
    * src/mod_rivet/rivet_worker_mpm.c: exporting through
    the bridge_jump_table the names of bridge functions
    * src/mod_rivet/rivet_prefork_mpm.c: export of the
    bridge function through the jump table. Removed the
    empty server init function (it's field in the jump
    table set to NULL). Removed exit handler (we rely on
    the default exit handler)
    * src/mod_rivet/rivetCore.c: using the jump table
    to call the exit handler


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/rivetCore.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=1696494&r1=1696493&r2=1696494&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Tue Aug 18 20:15:43 2015
@@ -1,3 +1,19 @@
+2015-08-18 Massimo Manghi <mx...@apache.org>
+    * src/mod_rivet/mod_rivet.[c|h]: now calling MPM through
+    a bridge_jump_table structure with all the functions exported
+    by a bridge implementation. Created default exit handler
+    so that only if a special exit handler is needed it has
+    to be defined
+    * src/mod_rivet/rivet_worker_mpm.c: exporting through
+    the bridge_jump_table the names of bridge functions
+    * src/mod_rivet/rivet_prefork_mpm.c: export of the
+    bridge function through the jump table. Removed the
+    empty server init function (it's field in the jump
+    table set to NULL). Removed exit handler (we rely on
+    the default exit handler)
+    * src/mod_rivet/rivetCore.c: using the jump table
+    to call the exit handler
+
 2015-07-15 Massimo Manghi <mx...@apache.org>
     * src/mod_rivet/rivet_worker_mpm.c: when thread private data
     are released the correponding pointer is set to NULL in APR 

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=1696494&r1=1696493&r2=1696494&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet.c Tue Aug 18 20:15:43 2015
@@ -61,9 +61,9 @@
 
 rivet_interp_globals    interp_globals;
 
-extern Tcl_ChannelType  RivetChan;
-apr_threadkey_t*        rivet_thread_key    = NULL;
-mod_rivet_globals*      module_globals      = NULL;
+extern Tcl_ChannelType   RivetChan;
+apr_threadkey_t*         rivet_thread_key    = NULL;
+mod_rivet_globals*       module_globals      = NULL;
 
 void        Rivet_PerInterpInit (   rivet_thread_interp* interp, 
                                     rivet_thread_private* private, 
@@ -73,6 +73,17 @@ int         Rivet_InitCore          (Tcl
 
 #define ERRORBUF_SZ     256
 
+/*
+ *
+ */
+
+int Rivet_Exit_Handler(int code)
+{
+    Tcl_Exit(code);
+    /*NOTREACHED*/
+    return TCL_OK;		/* Better not ever reach this! */
+}
+
 /* -- Rivet_PrintErrorMessage
  *
  * Utility function to print the error message stored in errorInfo
@@ -283,7 +294,7 @@ rivet_thread_private* Rivet_VirtualHosts
 
     root_server_conf = RIVET_SERVER_CONF (root_server->module_config);
     
-    root_interp = (*module_globals->mpm_master_interp)();
+    root_interp = (*RIVET_MPM_BRIDGE_FUNCTION(mpm_master_interp))();
 
     /* we must assume the module was able to create the root interprter */ 
 
@@ -1456,7 +1467,6 @@ Rivet_RunServerInit (apr_pool_t *pPool,
         Tcl_DecrRefCount(server_init);
     }
 
-
     return OK;
 
 }
@@ -1536,90 +1546,30 @@ Rivet_ServerInit (apr_pool_t *pPool, apr
         apr_status_t                rv;
         apr_dso_handle_sym_t        func = NULL;
 
-        ap_log_error(APLOG_MARK,APLOG_INFO,0,server,"MPM bridge loaded: %s",mpm_model_path);
+        ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,"MPM bridge loaded: %s",mpm_model_path);
 
-        rv = apr_dso_sym(&func,dso_handle,"Rivet_MPM_ServerInit");
+        rv = apr_dso_sym(&func,dso_handle,"bridge_jump_table");
         if (rv == APR_SUCCESS)
         {
-            module_globals->mpm_server_init = (int (*)(apr_pool_t*,apr_pool_t*,apr_pool_t*,server_rec*))func;
+            module_globals->bridge_jump_table = (rivet_bridge_table*) func;
         }
         else
         {
             ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
-                         MODNAME ": Error loading symbol Rivet_MPM_ServerInit: %s", 
+                         MODNAME ": Error loading symbol bridge_jump_table: %s", 
                          apr_dso_error(dso_handle,errorbuf,ERRORBUF_SZ));
             exit(1);   
         }
 
-        rv = apr_dso_sym(&func,dso_handle,"Rivet_MPM_ChildInit");
-        if (rv == APR_SUCCESS)
-        {
-            module_globals->mpm_child_init = (int (*)(apr_pool_t*,server_rec*)) func;
-        }
-        else
-        {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
-                         MODNAME ": Error loading symbol Rivet_MPM_Init: %s", 
-                         apr_dso_error(dso_handle,errorbuf,ERRORBUF_SZ));
-            exit(1);   
-        }
+        /* we require only mpm_request and mpm_master_interp to be defined */
 
-        rv = apr_dso_sym(&func,dso_handle,"Rivet_MPM_Request");
-        if (rv == APR_SUCCESS)
-        {
-            module_globals->mpm_request = (int (*)(request_rec*)) func;
-        }
-        else
-        {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
-                         MODNAME ": Error loading symbol Rivet_MPM_Request: %s", 
-                         apr_dso_error(dso_handle,errorbuf,ERRORBUF_SZ));
-            exit(1);   
-        }
+        ap_assert(RIVET_MPM_BRIDGE_FUNCTION(mpm_request) != NULL);
+        ap_assert(RIVET_MPM_BRIDGE_FUNCTION(mpm_master_interp) != NULL);
 
-        rv = apr_dso_sym(&func,dso_handle,"Rivet_MPM_Finalize");
-        if (rv == APR_SUCCESS)
-        {
-            module_globals->mpm_finalize = (apr_status_t (*)(void *)) func;
+        if (RIVET_MPM_BRIDGE_FUNCTION(mpm_exit_handler) == NULL) {
+            RIVET_MPM_BRIDGE_FUNCTION(mpm_exit_handler) = Rivet_Exit_Handler;
         }
-        else
-        {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
-                         MODNAME ": Error loading symbol Rivet_MPM_Finalize: %s", 
-                         apr_dso_error(dso_handle,errorbuf,ERRORBUF_SZ));
-            exit(1);   
-        }
-
-        rv = apr_dso_sym(&func,dso_handle,"Rivet_MPM_MasterInterp");
-        if (rv == APR_SUCCESS)
-        {
-            module_globals->mpm_master_interp = (rivet_thread_interp* (*)(void)) func;
-        }
-        else
-        {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
-                         MODNAME ": Error loading symbol Rivet_MPM_MasterInterp: %s", 
-                         apr_dso_error(dso_handle,errorbuf,ERRORBUF_SZ));
-            exit(1);   
-        }
-
-        rv = apr_dso_sym(&func,dso_handle,"Rivet_MPM_ExitHandler");
-        if (rv == APR_SUCCESS)
-        {
-            module_globals->mpm_exit_handler = (int (*)(int)) func;
-        }
-        else
-        {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_EGENERAL, server, 
-                         MODNAME ": Error loading symbol Rivet_MPM_ExitHandler: %s", 
-                         apr_dso_error(dso_handle,errorbuf,ERRORBUF_SZ));
-            exit(1);   
 
-        }
-
-
-        /* active threads count */
-        
         apr_atomic_init(pPool);
         apr_thread_mutex_create(&module_globals->pool_mutex, APR_THREAD_MUTEX_UNNESTED, pPool);
 
@@ -1649,7 +1599,9 @@ Rivet_ServerInit (apr_pool_t *pPool, apr
 
     Rivet_RunServerInit(pPool,pLog,pTemp,server);
 
-    return (*module_globals->mpm_server_init)(pPool,pLog,pTemp,server);
+    RIVET_MPM_BRIDGE_CALL(mpm_server_init,pPool,pLog,pTemp,server);
+
+    return OK;
 }
 
 static void Rivet_ChildInit (apr_pool_t *pChild, server_rec *server)
@@ -1705,13 +1657,25 @@ static void Rivet_ChildInit (apr_pool_t
 
     /* Calling the brigde child process initialization */
 
-    (*module_globals->mpm_child_init)(pChild,server);
-    apr_pool_cleanup_register (pChild, server, module_globals->mpm_finalize, module_globals->mpm_finalize);
+    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));
+    }
 }
 
 static int Rivet_Handler (request_rec *r)    
 {
-    return (*module_globals->mpm_request)(r);
+    return (*RIVET_MPM_BRIDGE_FUNCTION(mpm_request))(r);
 }
 
 /*

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=1696494&r1=1696493&r2=1696494&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/mod_rivet.h (original)
+++ tcl/rivet/trunk/src/mod_rivet/mod_rivet.h Tue Aug 18 20:15:43 2015
@@ -162,35 +162,41 @@ typedef struct _rivet_thread_interp {
     unsigned int        flags;              /* signals of various interp specific conditions    */
 } rivet_thread_interp;
 
+typedef int  (RivetBridge_ServerInit)   (apr_pool_t*,apr_pool_t*,apr_pool_t*,server_rec*);
+typedef void (RivetBridge_ChildInit)    (apr_pool_t* pPool,server_rec* s);
+typedef int  (RivetBridge_Request)      (request_rec*);
+typedef apr_status_t 
+             (RivetBridge_Finalize)(void*);
+typedef rivet_thread_interp*
+             (RivetBridge_Master_Interp) (void);
+typedef int  (RivetBridge_Exit_Handler) (int);
+
+typedef struct _mpm_bridge_table {
+    RivetBridge_ServerInit    *mpm_server_init;
+    RivetBridge_ChildInit     *mpm_child_init;
+    RivetBridge_Request       *mpm_request;
+    RivetBridge_Finalize      *mpm_finalize;
+    RivetBridge_Master_Interp *mpm_master_interp;
+    RivetBridge_Exit_Handler  *mpm_exit_handler;
+} rivet_bridge_table;
+
 /* we need also a place where to store module wide globals */
 
 typedef struct mpm_bridge_status mpm_bridge_status;
 
 typedef struct _mod_rivet_globals {
     apr_pool_t*         pool;               
-    char*               rivet_mpm_bridge;       /* name of the MPM bridge               */
-    server_rec*         server;                 /* default host server_rec obj          */
+    char*               rivet_mpm_bridge;       /* name of the MPM bridge                   */
+    server_rec*         server;                 /* default host server_rec obj              */
     int                 vhosts_count;           /* Number of configured virtual host including 
                                                  * the root server thus it's supposed to be >= 1 */
     rivet_thread_interp* 
-                        server_interp;          /* server and prefork MPM interpreter   */
-    apr_thread_mutex_t* pool_mutex;             /* threads commmon pool mutex           */
-
-    /* Jump table to bridge specific procedures */
+                        server_interp;          /* server and prefork MPM interpreter       */
+    apr_thread_mutex_t* pool_mutex;             /* threads commmon pool mutex               */
 
-    int                 (*mpm_child_init)(apr_pool_t* pPool,server_rec* s);
-    int                 (*mpm_request)(request_rec*);
-    int                 (*mpm_server_init)(apr_pool_t*,apr_pool_t*,apr_pool_t*,server_rec*);
-    apr_status_t        (*mpm_finalize)(void*);
-    rivet_thread_interp* (*mpm_master_interp)(void);
-    int                 (*mpm_exit_handler)(int);
-
-    mpm_bridge_status*  mpm;
-
-    /*
-    int                 num_load_samples;
-    double              average_working_threads; 
-    */
+    rivet_bridge_table* bridge_jump_table;     /* Jump table to bridge specific procedures  */
+    mpm_bridge_status*  mpm;                   /* bridge private control structure          */
+    
 #ifdef RIVET_SERIALIZE_HTTP_REQUESTS
     apr_thread_mutex_t* req_mutex;
 #endif
@@ -325,5 +331,11 @@ EXTERN Tcl_Interp* Rivet_CreateTclInterp
         Tcl_IncrRefCount(running_script->objscript);\
     }
 
+#define RIVET_MPM_BRIDGE_TABLE         bridge_jump_table
+#define RIVET_MPM_BRIDGE_FUNCTION(fun) module_globals->bridge_jump_table->fun
+
+#define RIVET_MPM_BRIDGE_CALL(fun,...) if ((*module_globals->bridge_jump_table->fun) != NULL) {\
+    (*module_globals->bridge_jump_table->fun)(__VA_ARGS__);\
+}
 
 #endif /* MOD_RIVET_H */

Modified: tcl/rivet/trunk/src/mod_rivet/rivetCore.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/mod_rivet/rivetCore.c?rev=1696494&r1=1696493&r2=1696494&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivetCore.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivetCore.c Tue Aug 18 20:15:43 2015
@@ -1351,7 +1351,7 @@ TCL_CMD_HEADER( Rivet_ExitCmd )
      * as it eventually will call Tcl_Exit
      */
 
-    return (*module_globals->mpm_exit_handler)(value);
+    return (*module_globals->bridge_jump_table->mpm_exit_handler)(value);
 }
 /*
  *-----------------------------------------------------------------------------

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=1696494&r1=1696493&r2=1696494&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivet_prefork_mpm.c Tue Aug 18 20:15:43 2015
@@ -46,7 +46,7 @@ apr_status_t Rivet_MPM_Finalize (void* d
     rivet_thread_private*   private;
     server_rec* s = (server_rec*) data;
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, s, MODNAME ": Running prefork bridge Finalize method");
+    ap_log_error(APLOG_MARK, APLOG_DEBUG, APR_EGENERAL, s, MODNAME ": Running prefork bridge finalize method");
     ap_assert (apr_threadkey_private_get ((void **)&private,rivet_thread_key) == APR_SUCCESS);
 
     Rivet_ProcessorCleanup(private);
@@ -55,7 +55,7 @@ apr_status_t Rivet_MPM_Finalize (void* d
     return OK;
 }
 
-int Rivet_MPM_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s) { return OK; }
+//int Rivet_MPM_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s) { return OK; }
 
 void Rivet_MPM_ChildInit (apr_pool_t* pool, server_rec* server)
 {
@@ -146,10 +146,19 @@ rivet_thread_interp* Rivet_MPM_MasterInt
  *
  */
 
-int Rivet_MPM_ExitHandler(int code)
-{
-    Tcl_Exit(code);
-    /*NOTREACHED*/
-    return TCL_OK;		/* Better not ever reach this! */
-}
+//int Rivet_MPM_ExitHandler(int code)
+//{
+//    Tcl_Exit(code);
+//    /*NOTREACHED*/
+//    return TCL_OK;		/* Better not ever reach this! */
+//}
+
+rivet_bridge_table bridge_jump_table = {
+    NULL,
+    Rivet_MPM_ChildInit,
+    Rivet_MPM_Request,
+    Rivet_MPM_Finalize,
+    Rivet_MPM_MasterInterp,
+    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=1696494&r1=1696493&r2=1696494&view=diff
==============================================================================
--- tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c (original)
+++ tcl/rivet/trunk/src/mod_rivet/rivet_worker_mpm.c Tue Aug 18 20:15:43 2015
@@ -375,10 +375,7 @@ static void* APR_THREAD_FUNC threaded_br
     return NULL;
 }
 
-int Rivet_MPM_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s)
-{
-    return OK;
-}
+// int Rivet_MPM_ServerInit (apr_pool_t *pPool, apr_pool_t *pLog, apr_pool_t *pTemp, server_rec *s) { return OK; }
 
 /*
  * -- Rivet_MPM_ChildInit
@@ -659,3 +656,12 @@ int Rivet_MPM_ExitHandler(int code)
 
     return TCL_ERROR;
 }
+
+rivet_bridge_table bridge_jump_table = {
+    NULL,
+    Rivet_MPM_ChildInit,
+    Rivet_MPM_Request,
+    Rivet_MPM_Finalize,
+    Rivet_MPM_MasterInterp,
+    Rivet_MPM_ExitHandler
+};



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