]> granicus.if.org Git - apache/commitdiff
Begin restructuring scoreboard code to enable adding back in
authorBill Stoddard <stoddard@apache.org>
Fri, 2 Feb 2001 21:32:34 +0000 (21:32 +0000)
committerBill Stoddard <stoddard@apache.org>
Fri, 2 Feb 2001 21:32:34 +0000 (21:32 +0000)
the ability to use IPC other than shared memory.
Get mod_status working on Windows again.

Still to do:
Rename some of the function APIs. Replace all calls to reinit_scoreboard with
ap_create_scoreboard. Add back in support for scoreboard files.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87959 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/scoreboard.h
libhttpd.dsp
modules/cache/mod_file_cache.dsp
modules/generators/mod_status.c
modules/generators/mod_status.dsp
server/mpm/winnt/mpm.h
server/mpm/winnt/mpm_default.h
server/mpm/winnt/mpm_winnt.c
server/mpm/winnt/mpm_winnt.h
server/scoreboard.c

diff --git a/CHANGES b/CHANGES
index 2b9f3c2d703f37285744b4a87c4047da51c681bf..e0c7a601f2e2ee486f8567250ade619dffd7c0cf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,7 @@
 Changes with Apache 2.0b1
+  *) Begin restructuring scoreboard code to enable adding back in
+     the ability to use IPC other than shared memory.
+     Get mod_status working on Windows again. [Bill Stoddard]
 
   *) Make mod_status work with 2.0.  This will work for prefork,
      mpmt_pthread, and dexter.  [Ryan Bloom]
index 180fb73607f05d4ccac24e251b39855b899adf49..87047e9c2fcba69ff48c4f94a59fe3a163fb8d3d 100644 (file)
@@ -139,6 +139,14 @@ typedef unsigned vtime_t;
  */
 typedef int ap_generation_t;
 
+/* Is the scoreboard shared between processes or not? 
+ * Set by the MPM when the scoreboard is created.
+ */
+typedef enum {
+    SB_SHARED = 1,
+    SB_NOT_SHARED = 2
+} ap_scoreboard_e;
+
 /* stuff which is thread/process specific */
 typedef struct {
 #ifdef OPTIMIZE_TIMEOUTS
@@ -168,6 +176,7 @@ typedef struct {
 } short_score;
 
 typedef struct {
+    ap_scoreboard_e sb_type;
     ap_generation_t running_generation;        /* the generation of children which
                                          * should still be serving requests. */
 } global_score;
@@ -211,12 +220,13 @@ typedef struct {
 #endif
 
 AP_DECLARE(int) ap_exists_scoreboard_image(void);
+AP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
 void reinit_scoreboard(apr_pool_t *p);
 apr_status_t ap_cleanup_shared_mem(void *d);
 
 AP_DECLARE(void) reopen_scoreboard(apr_pool_t *p);
 
-apr_inline void ap_sync_scoreboard_image(void);
+void ap_sync_scoreboard_image(void);
 void increment_counts(int child_num, int thread_num, request_rec *r);
 void update_scoreboard_global(void);
 AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid);
index ea7bb495b9bc37bcc4890cc84a1a4a1e3cb8fe36..54ea27f524b4d197b9793557326d00a973cee353 100644 (file)
@@ -227,6 +227,10 @@ SOURCE=.\server\log.c
 # End Source File
 # Begin Source File
 
+SOURCE=.\server\scoreboard.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\server\vhost.c
 # End Source File
 # End Group
index 3d344554e96e410aa4fad5bd83021762d3192e0d..58786f2e40c2b30659ca69d91fc0be172f479b7c 100644 (file)
@@ -52,8 +52,8 @@ BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
 LINK32=link.exe
-# ADD BASE LINK32 /nologo /subsystem:windows /dll /incremental:no /map /out:"Release/mod_file_cache.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
-# ADD LINK32 /nologo /subsystem:windows /dll /incremental:no /map /out:"Release/mod_file_cache.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
+# ADD BASE LINK32 /nologo /subsystem:windows /dll /map /machine:I386 /out:"Release/mod_file_cache.so" /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
+# ADD LINK32 /nologo /subsystem:windows /dll /map /machine:I386 /out:"Release/mod_file_cache.so" /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
 
 !ELSEIF  "$(CFG)" == "mod_file_cache - Win32 Debug"
 
@@ -78,8 +78,8 @@ BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
 LINK32=link.exe
-# ADD BASE LINK32 /nologo /subsystem:windows /dll /incremental:no /map /debug /out:"Debug/mod_file_cache.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
-# ADD LINK32 /nologo /subsystem:windows /dll /incremental:no /map /debug /out:"Debug/mod_file_cache.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
+# ADD BASE LINK32 /nologo /subsystem:windows /dll /incremental:no /map /debug /machine:I386 /out:"Debug/mod_file_cache.so" /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
+# ADD LINK32 /nologo /subsystem:windows /dll /incremental:no /map /debug /machine:I386 /out:"Debug/mod_file_cache.so" /base:@..\..\os\win32\BaseAddr.ref,mod_file_cache
 
 !ENDIF 
 
index 64314bd542e83c4e32fa0b5f40182ad49560c289..989076f12467dcd08457afc08f636cf824f796f5 100644 (file)
@@ -308,7 +308,7 @@ static int status_handler(request_rec *r)
     if (r->header_only)
        return 0;
 
-    ap_sync_scoreboard_image();
+/*    ap_sync_scoreboard_image(); */
     for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
         for (j = 0; j < HARD_THREAD_LIMIT; ++j) {
             int indx = (i * HARD_THREAD_LIMIT) + j;
index 36ff558fe6562469548a59b4269e344721b05f78..01e117238b540233aa35e22392b823c45605a768 100644 (file)
@@ -43,7 +43,7 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
-# ADD CPP /nologo /MD /W3 /O2 /I "..\..\include" /I "..\..\os\win32" /I "..\..\srclib\apr\include" /I "../../srclib/apr-util/include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fd"Release\mod_status" /FD /c
+# ADD CPP /nologo /MD /W3 /O2 /I "..\..\include" /I "..\..\os\win32" /I "..\..\srclib\apr\include" /I "../../srclib/apr-util/include" /I "../../server/mpm/winnt" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /Fd"Release\mod_status" /FD /c
 # ADD BASE MTL /nologo /D "NDEBUG" /win32
 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x809 /d "NDEBUG"
@@ -52,8 +52,8 @@ BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
 LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /out:"Release/mod_status.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_status
-# ADD LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /out:"Release/mod_status.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_status
+# ADD BASE LINK32 kernel32.lib /nologo /subsystem:windows /dll /map /machine:I386 /out:"Release/mod_status.so" /base:@..\..\os\win32\BaseAddr.ref,mod_status
+# ADD LINK32 kernel32.lib /nologo /subsystem:windows /dll /map /machine:I386 /out:"Release/mod_status.so" /base:@..\..\os\win32\BaseAddr.ref,mod_status
 
 !ELSEIF  "$(CFG)" == "mod_status - Win32 Debug"
 
@@ -69,7 +69,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0
 # PROP Target_Dir ""
 # ADD BASE CPP /nologo /MDd /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
-# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\..\include" /I "..\..\os\win32" /I "..\..\srclib\apr\include" /I "../../srclib/apr-util/include" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /Fd"Debug\mod_status" /FD /c
+# ADD CPP /nologo /MDd /W3 /GX /ZI /Od /I "..\..\include" /I "..\..\os\win32" /I "..\..\srclib\apr\include" /I "../../srclib/apr-util/include" /I "../../server/mpm/winnt" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /Fd"Debug\mod_status" /FD /c
 # ADD BASE MTL /nologo /D "_DEBUG" /win32
 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
 # ADD BASE RSC /l 0x809 /d "_DEBUG"
@@ -78,8 +78,8 @@ BSC32=bscmake.exe
 # ADD BASE BSC32 /nologo
 # ADD BSC32 /nologo
 LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug /out:"Debug/mod_status.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_status
-# ADD LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug /out:"Debug/mod_status.so" /machine:I386 /base:@..\..\os\win32\BaseAddr.ref,mod_status
+# ADD BASE LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug /machine:I386 /out:"Debug/mod_status.so" /base:@..\..\os\win32\BaseAddr.ref,mod_status
+# ADD LINK32 kernel32.lib /nologo /subsystem:windows /dll /incremental:no /map /debug /machine:I386 /out:"Debug/mod_status.so" /base:@..\..\os\win32\BaseAddr.ref,mod_status
 
 !ENDIF 
 
index c88bc4a46dfb3ee8c390fa581a6f469ec5702a12..91e366e8e3f4d5adb02a3dbce9ccce6e0e1a86a8 100644 (file)
 #ifndef APACHE_MPM_H
 #define APACHE_MPM_H
 
+/* mpm.h is the place to make declarations that are MPM specific but that must be 
+ * shared with non-mpm specific code in the server.  Hummm, perhaps we can
+ * move most of this stuff to mpm_common.h?
+ */
+extern int ap_threads_per_child;
 
 #endif /* APACHE_MPM_H */
index 056ab1d57b643bfbd2ba300d76959eb51ce889e0..a0725128afbdf5d01f52bc5a868aacebc696c318 100644 (file)
@@ -59,6 +59,9 @@
 #ifndef APACHE_MPM_DEFAULT_H
 #define APACHE_MPM_DEFAULT_H
 
+/* AP_CHILD_THREAD_FROM_ID is used by the scoreboard.  */
+#define AP_CHILD_THREAD_FROM_ID(i)       i, 0
+
 /* Number of threads to spawn off by default --- also, if fewer than
  * this free when the caretaker checks, it will spawn more.
  */
index 3da8215eab0d5567aee258ed9f1a256c9c5e86f6..225b611fd14c804c199bfda264b30c037617f70a 100644 (file)
@@ -1,3 +1,4 @@
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
 #include "mpm_default.h"
 #include "mpm_winnt.h"
 #include "mpm_common.h"
+#include "scoreboard.h"
 
 typedef HANDLE thread;
 
 /*
  * Definitions of WINNT MPM specific config globals
  */
+
 static int workers_may_exit = 0;
 static int shutdown_in_progress = 0;
 static unsigned int g_blocked_threads = 0;
 
 static char *ap_pid_fname = NULL;
-static int ap_threads_per_child = 0;
+int ap_threads_per_child = 0;
 
 static int max_requests_per_child = 0;
 static HANDLE shutdown_event;  /* used to signal shutdown to parent */
@@ -119,6 +122,15 @@ apr_lock_t *start_mutex;
 DWORD my_pid;
 DWORD parent_pid;
 
+/* ap_get_max_daemons and ap_my_generation are used by the scoreboard
+ * code
+ */
+ap_generation_t volatile ap_my_generation=0; /* Used by the scoreboard */
+AP_DECLARE(int) ap_get_max_daemons(void)
+{
+    return 1;
+}
+
 /* This is the helper code to resolve late bound entry points 
  * missing from one or more releases of the Win32 API...
  * but it sure would be nice if we didn't duplicate this code
@@ -1216,6 +1228,10 @@ static void child_main()
     int cld;
     apr_pool_t *pchild;
 
+    /* Set up the scoreboard. The scoreboard in this MPM only applies to the
+     * child process and is not shared across processes
+     */
+    ap_create_scoreboard(pconf, SB_NOT_SHARED);
 
     /* This is the child process or we are running in single process
      * mode.
index d57e40d6b1eb27770b67362272ad519545c25ae4..5e41b1d0b597c493ea37bc140c6acdc8a19274ae 100644 (file)
@@ -114,9 +114,7 @@ void mpm_start_child_console_handler(void);
 /* From winnt.c: */
 
 extern OSVERSIONINFO osver;
-extern int ap_threads_per_child;
 extern int ap_max_requests_per_child;
-extern int ap_extended_status;
 extern void clean_child_exit(int);
 
 AP_DECLARE(void) ap_start_shutdown(void);
index e36bb892227cf667f2acb94e7e03321007426a12..795c95fb2017d493d8390231fe93f92a6735be3e 100644 (file)
 #include "http_main.h"
 #include "http_core.h"
 #include "http_config.h"
+/* ToDo: Fix this right */
+#ifndef WIN32
 #include "unixd.h"
+#endif
+
 #include "http_conf_globals.h"
 #include "mpm.h"
 #include "scoreboard.h"
@@ -79,20 +83,33 @@ AP_DECLARE_DATA apr_time_t ap_restart_time = 0;
 
 #if APR_HAS_SHARED_MEMORY
 #include "apr_shmem.h"
-
 static apr_shmem_t *scoreboard_shm = NULL;
-
+#endif
+/*
+ * ToDo:
+ * This function should be renamed to cleanup_shared
+ * and it should handle cleaning up a scoreboard shared
+ * between processes using any form of IPC (file, shared memory
+ * segment, etc.). Leave it as is now because it is being used
+ * by various MPMs. 
+ */
 apr_status_t ap_cleanup_shared_mem(void *d)
 {
+#if APR_HAD_SHARED_MEMORY
     apr_shm_free(scoreboard_shm, ap_scoreboard_image);
     ap_scoreboard_image = NULL;
     apr_shm_destroy(scoreboard_shm);
-
+#endif
     return APR_SUCCESS;
 }
 
-static void setup_shared_mem(apr_pool_t *p)
+/* ToDo: This function should be made to handle setting up 
+ * a scoreboard shared between processes using any IPC technique, 
+ * not just a shared memory segment
+ */
+static void setup_shared(apr_pool_t *p)
 {
+#if APR_HAD_SHARED_MEMORY
     char buf[512];
     char errmsg[120];
     const char *fname;
@@ -114,26 +131,69 @@ static void setup_shared_mem(apr_pool_t *p)
         apr_shm_destroy(scoreboard_shm);
         exit(APEXIT_INIT);
     }
-    apr_register_cleanup(p, NULL, ap_cleanup_shared_mem, apr_null_cleanup);
     ap_scoreboard_image->global.running_generation = 0;
+#endif
 }
 
-void reopen_scoreboard(apr_pool_t *p)
+AP_DECLARE(void) reopen_scoreboard(apr_pool_t *p)
 {
 }
-#endif   /* APR_SHARED_MEM */
 
-/* Called by parent process */
-void reinit_scoreboard(apr_pool_t *p)
+/* ap_cleanup_scoreboard
+ * 
+ */
+static void ap_cleanup_scoreboard(void *d) {
+    if (ap_scoreboard_image == NULL)
+        return;
+    if (ap_scoreboard_image->global.sb_type == SB_SHARED) {
+        ap_cleanup_shared_mem(NULL);
+    }
+    else {
+        free(ap_scoreboard_image);
+        ap_scoreboard_image = NULL;
+    }
+}
+
+/* ap_create_scoreboard(apr_pool_t*, ap_scoreboard_e t)
+ *
+ * Create or reinit an existing scoreboard. The MPM can control whether
+ * the scoreboard is shared across multiple processes or not
+ */
+AP_DECLARE(void) ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
 {
     int running_gen = 0;
     if (ap_scoreboard_image)
        running_gen = ap_scoreboard_image->global.running_generation;
     if (ap_scoreboard_image == NULL) {
-        setup_shared_mem(p);
+        if (sb_type == SB_SHARED) {
+            setup_shared(p);
+            ap_scoreboard_image->global.sb_type = SB_SHARED;
+        }
+        else {
+            /* A simple malloc will suffice */
+            char buf[512];
+            ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
+            if (ap_scoreboard_image == NULL) {
+                apr_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
+                             ap_server_argv0);
+                perror(buf); /* o.k. since MM sets errno */
+                exit(APEXIT_INIT);            
+            }
+            ap_scoreboard_image->global.sb_type = SB_NOT_SHARED;
+        }
     }
     memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
     ap_scoreboard_image->global.running_generation = running_gen;
+    apr_register_cleanup(p, NULL, ap_cleanup_scoreboard, apr_null_cleanup);
+}
+
+/* ToDo:
+ * reinit_scoreboard should be eliminated when all MPMs migrate to
+ * ap_create_scoreboard()
+ */
+void reinit_scoreboard(apr_pool_t *p)
+{
+    ap_create_scoreboard(p, SB_SHARED);
 }
 
 /* Routines called to deal with the scoreboard image
@@ -147,7 +207,7 @@ void reinit_scoreboard(apr_pool_t *p)
  * anyway.
  */
 
-apr_inline void ap_sync_scoreboard_image(void)
+void ap_sync_scoreboard_image(void)
 {
 }