tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r702160 - /tomcat/connectors/trunk/jk/native/common/jk_shm.c
Date Mon, 06 Oct 2008 14:28:21 GMT
Author: mturk
Date: Mon Oct  6 07:28:20 2008
New Revision: 702160

URL: http://svn.apache.org/viewvc?rev=702160&view=rev
Log:
Implement global shared memory lock for IIS. With IIS 6+ we don't have a single process any
more

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

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=702160&r1=702159&r2=702160&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_shm.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_shm.c Mon Oct  6 07:28:20 2008
@@ -81,6 +81,7 @@
 static time_t jk_workers_access_time = 0;
 #if defined (WIN32)
 static HANDLE jk_shm_map = NULL;
+static HANDLE jk_shm_hlock = NULL;
 #endif
 
 /* Calculate needed shm size */
@@ -150,6 +151,7 @@
 {
     int rc;
     int attached = 0;
+    char lkname[MAX_PATH];
     JK_TRACE_ENTER(l);
     if (jk_shmem.hdr) {
         if (JK_IS_DEBUG_LEVEL(l))
@@ -178,6 +180,19 @@
             JK_TRACE_EXIT(l);
             return -1;
         }
+        sprintf(lkname, "Global\\%s_MUTEX", fname);
+        if (attached) {
+            jk_shm_hlock = OpenMutex(MUTEX_ALL_ACCESS, FALSE, lkname);
+        }
+        else {
+            jk_shm_hlock = CreateMutex(NULL, FALSE, lkname);            
+        }
+        if (jk_shm_hlock == NULL || jk_shm_hlock == INVALID_HANDLE_VALUE) {
+            CloseHandle(jk_shm_map);
+            jk_shm_map = NULL;
+            JK_TRACE_EXIT(l);
+            return -1;
+        }
         jk_shmem.hdr = (jk_shm_header_t *)MapViewOfFile(jk_shm_map,
                                                         FILE_MAP_ALL_ACCESS,
                                                         0,
@@ -193,6 +208,10 @@
             CloseHandle(jk_shm_map);
             jk_shm_map = NULL;
         }
+        if (jk_shm_hlock) {
+            CloseHandle(jk_shm_hlock);
+            jk_shm_hlock = NULL;
+        }
 #endif
         JK_TRACE_EXIT(l);
         return -1;
@@ -270,6 +289,10 @@
     if (jk_shmem.hdr) {
         int rc;
 #if defined (WIN32)
+        if (jk_shm_hlock) {
+            CloseHandle(jk_shm_hlock);
+            jk_shm_hlock = NULL;
+        }
         if (jk_shm_map) {
             --jk_shmem.hdr->h.data.childs;
             UnmapViewOfFile(jk_shmem.hdr);
@@ -707,9 +730,19 @@
 {
     int rc;
     JK_ENTER_CS(&(jk_shmem.cs), rc);
+#if defined (WIN32)
+    if (rc == JK_TRUE && jk_shm_hlock != NULL) {
+        DWORD rv = WaitForSingleObject(jk_shm_hlock, INFINITE);
+        if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED)
+            rc = JK_TRUE;
+        else
+            rc = JK_FALSE;         
+    }
+#else    
     if (rc == JK_TRUE && jk_shmem.fd_lock != -1) {
         JK_ENTER_LOCK(jk_shmem.fd_lock, rc);
     }
+#endif
     return rc;
 }
 
@@ -717,9 +750,16 @@
 {
     int rc;
     JK_LEAVE_CS(&(jk_shmem.cs), rc);
+#if defined (WIN32)
+    if (rc == JK_TRUE && jk_shm_hlock != NULL) {
+        if (!ReleaseMutex(jk_shm_hlock))
+            rc = JK_FALSE;         
+    }
+#else    
     if (rc == JK_TRUE && jk_shmem.fd_lock != -1) {
         JK_LEAVE_LOCK(jk_shmem.fd_lock, rc);
     }
+#endif
     return rc;
 }
 



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


Mime
View raw message