You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2008/01/06 15:12:43 UTC

svn commit: r609314 - in /tomcat/connectors/trunk/jk/native/common: jk_shm.c jk_shm.h

Author: rjung
Date: Sun Jan  6 06:12:42 2008
New Revision: 609314

URL: http://svn.apache.org/viewvc?rev=609314&view=rev
Log:
Add function to calculate needed shm size.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_shm.c
    tomcat/connectors/trunk/jk/native/common/jk_shm.h

Modified: tomcat/connectors/trunk/jk/native/common/jk_shm.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_shm.c?rev=609314&r1=609313&r2=609314&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_shm.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_shm.c Sun Jan  6 06:12:42 2008
@@ -26,6 +26,7 @@
 #include "jk_pool.h"
 #include "jk_util.h"
 #include "jk_mt.h"
+#include "jk_lb_worker.h"
 #include "jk_shm.h"
 
 /** jk shm header core data structure */
@@ -58,6 +59,7 @@
 struct jk_shm
 {
     size_t     size;
+    unsigned   workers;
     char       *filename;
     char       *lockname;
     int        fd;
@@ -70,12 +72,57 @@
 typedef struct jk_shm jk_shm_t;
 
 static const char shm_signature[] = { JK_SHM_MAGIC };
-static jk_shm_t jk_shmem = { 0, NULL, NULL, -1, -1, 0, NULL};
+static jk_shm_t jk_shmem = { 0, 0, NULL, NULL, -1, -1, 0, NULL};
 static time_t jk_workers_modified_time = 0;
 static time_t jk_workers_access_time = 0;
 #if defined (WIN32)
 static HANDLE jk_shm_map = NULL;
 #endif
+
+/* Calculate needed shm size */
+size_t jk_shm_calculate_size(jk_map_t *init_data, jk_logger_t *l)
+{
+    char **worker_list;
+    unsigned i;
+    unsigned num_of_workers;
+    int num_of_shm_workers = 0;
+
+    JK_TRACE_ENTER(l);
+
+    if (jk_get_worker_list(init_data, &worker_list,
+                           &num_of_workers) == JK_FALSE) {
+        jk_log(l, JK_LOG_ERROR,
+               "Could not get worker list from map");
+        JK_TRACE_EXIT(l);
+        return 0;
+    }
+
+    for (i = 0; i < num_of_workers; i++) {
+        const char *type = jk_get_worker_type(init_data, worker_list[i]);
+
+        if (!strcmp(type, JK_LB_WORKER_NAME)) {
+            char **member_list;
+            unsigned num_of_members;
+            if (jk_get_lb_worker_list(init_data, worker_list[i],
+                                      &member_list, &num_of_members) == JK_FALSE) {
+                jk_log(l, JK_LOG_ERROR,
+                       "Could not get member list for lb worker from map");
+                JK_TRACE_EXIT(l);
+                return 0;
+            }
+            if (JK_IS_DEBUG_LEVEL(l))
+                jk_log(l, JK_LOG_DEBUG, "worker %s of type %s has %u members",
+                       worker_list[i], JK_LB_WORKER_NAME, num_of_members);
+            num_of_shm_workers += num_of_members + 1;
+        }
+    }
+    if (JK_IS_DEBUG_LEVEL(l))
+        jk_log(l, JK_LOG_DEBUG, "shared memory will contain %u items", num_of_shm_workers);
+    jk_shmem.workers = num_of_shm_workers;
+    JK_TRACE_EXIT(l);
+    return JK_SHM_SIZE(jk_shmem.workers);
+}
+
 
 #if defined (WIN32) || defined(NETWARE)
 

Modified: tomcat/connectors/trunk/jk/native/common/jk_shm.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_shm.h?rev=609314&r1=609313&r2=609314&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_shm.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_shm.h Sun Jan  6 06:12:42 2008
@@ -51,9 +51,10 @@
 /* Really huge numbers, but 64 workers should be enough */
 #define JK_SHM_MAX_WORKERS  64
 #define JK_SHM_WORKER_SIZE  JK_SHM_ALIGN(sizeof(jk_shm_worker_t))
-#define JK_SHM_DEF_SIZE     (JK_SHM_MAX_WORKERS * JK_SHM_WORKER_SIZE)
+#define JK_SHM_SIZE(x)      ((x) * JK_SHM_WORKER_SIZE)
+#define JK_SHM_DEF_SIZE     JK_SHM_SIZE(JK_SHM_MAX_WORKERS)
 #define JK_SHM_ALIGNMENT    64
-#define JK_SHM_ALIGN(x)     JK_ALIGN(x, JK_SHM_ALIGNMENT)
+#define JK_SHM_ALIGN(x)     JK_ALIGN((x), JK_SHM_ALIGNMENT)
 
 /** jk shm worker record structure */
 struct jk_shm_worker
@@ -123,6 +124,9 @@
 typedef struct jk_shm_worker jk_shm_worker_t;
 
 const char *jk_shm_name(void);
+
+/* Calculate needed shm size */
+size_t jk_shm_calculate_size(jk_map_t *init_data, jk_logger_t *l);
 
 /* Open the shared memory creating file if needed
  */



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org