]> granicus.if.org Git - apache/commitdiff
Merge r1387088 from trunk:
authorJim Jagielski <jim@apache.org>
Thu, 4 Oct 2012 12:49:09 +0000 (12:49 +0000)
committerJim Jagielski <jim@apache.org>
Thu, 4 Oct 2012 12:49:09 +0000 (12:49 +0000)
Add in new type CLEARINUSE which allows the inuse table to
be cleared upon storage. This may be expected/wanted/required
by some applications

Reviewed/backported by: jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1394021 13f79535-47bb-0310-9956-ffa450edef68

STATUS
docs/manual/mod/mod_slotmem_shm.xml
include/ap_slotmem.h
modules/slotmem/mod_slotmem_shm.c

diff --git a/STATUS b/STATUS
index 98520bbd260cf74acbdeee0ebe2d4088c74d0b14..8d0b5505f73e48af101ae1130afa22b11a46b2e2 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -89,11 +89,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
   
-   * mod_slotmem_shm: New slotmem_shm type CLEARINUSE which clears this
-     table before persisting:
-     trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1387088
-      2.4.x patch: trunk patch works
-     +1: jim, humbedooh, rjung
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
index cee9a8e4ebf90437d97243d19b525a19a2f659c2..12b94f2688b33d76aa489ef081e60e17976ffd07 100644 (file)
       <dd>call the callback on all worker slots</dd>
 
       <dt>apr_status_t create(ap_slotmem_instance_t **new, const char *name, apr_size_t item_size, unsigned int item_num, ap_slotmem_type_t type, apr_pool_t *pool)</dt>
-      <dd>create a new slotmem with each item size is item_size. <code>name</code> is the filename for the persistent store of
-      the shared memory. Values are:
+      <dd>create a new slotmem with each item size is item_size. <code>name</code> is used to generate a filename for the persistent store of
+      the shared memory if configured. Values are:
        <dl>
          <dt><code>"none"</code></dt>
-         <dd><code>Does not persist shared memory in file.</code></dd>
+         <dd><code>Anonymous shared memory and no persistent store</code></dd>
          <dt><code>"file-name"</code></dt>
          <dd><code>[DefaultRuntimeDir]/file-name</code></dd>
          <dt><code>"/absolute-file-name"</code></dt>
index 496f455e69bcc17cf58247583e3968d2b6bd1ef8..3d4eafd4195c7d7630301ca734c81448d6cf133b 100644 (file)
@@ -62,10 +62,14 @@ typedef unsigned int ap_slotmem_type_t;
  * AP_SLOTMEM_TYPE_NOTMPSAFE:
  *
  * AP_SLOTMEM_TYPE_PREALLOC: Access to slots require they be grabbed 1st
+ *
+ * AP_SLOTMEM_TYPE_CLEARINUSE: If persisting, clear 'inuse' array before
+ *    storing
  */
-#define AP_SLOTMEM_TYPE_PERSIST   (1 << 0)
-#define AP_SLOTMEM_TYPE_NOTMPSAFE (1 << 1)
-#define AP_SLOTMEM_TYPE_PREGRAB   (1 << 2)
+#define AP_SLOTMEM_TYPE_PERSIST      (1 << 0)
+#define AP_SLOTMEM_TYPE_NOTMPSAFE    (1 << 1)
+#define AP_SLOTMEM_TYPE_PREGRAB      (1 << 2)
+#define AP_SLOTMEM_TYPE_CLEARINUSE   (1 << 3)
 
 typedef struct ap_slotmem_instance_t ap_slotmem_instance_t;
 
index 79776d43830850116951337b18818d8ecefb55ff..33acb48834bd366ce1d5568f725da4812dfffaee 100644 (file)
@@ -43,8 +43,9 @@
 #endif
 #endif
 
-#define AP_SLOTMEM_IS_PREGRAB(t) (t->desc.type & AP_SLOTMEM_TYPE_PREGRAB)
-#define AP_SLOTMEM_IS_PERSIST(t) (t->desc.type & AP_SLOTMEM_TYPE_PERSIST)
+#define AP_SLOTMEM_IS_PREGRAB(t)    (t->desc.type & AP_SLOTMEM_TYPE_PREGRAB)
+#define AP_SLOTMEM_IS_PERSIST(t)    (t->desc.type & AP_SLOTMEM_TYPE_PERSIST)
+#define AP_SLOTMEM_IS_CLEARINUSE(t) (t->desc.type & AP_SLOTMEM_TYPE_CLEARINUSE)
 
 /* The description of the slots to reuse the slotmem */
 typedef struct {
@@ -144,6 +145,25 @@ static const char *slotmem_filename(apr_pool_t *pool, const char *slotmemname)
     return fname;
 }
 
+static void slotmem_clearinuse(ap_slotmem_instance_t *slot)
+{
+    unsigned int i;
+    char *inuse;
+    
+    if (!slot) {
+        return;
+    }
+    
+    inuse = slot->inuse;
+    
+    for (i = 0; i < slot->desc.num; i++, inuse++) {
+        if (*inuse) {
+            *inuse = 0;
+            (*slot->num_free)++;
+        }
+    }
+}
+
 static void store_slotmem(ap_slotmem_instance_t *slotmem)
 {
     apr_file_t *fp;
@@ -164,6 +184,9 @@ static void store_slotmem(ap_slotmem_instance_t *slotmem)
         if (rv != APR_SUCCESS) {
             return;
         }
+        if (AP_SLOTMEM_IS_CLEARINUSE(slotmem)) {
+            slotmem_clearinuse(slotmem);
+        }
         nbytes = (slotmem->desc.size * slotmem->desc.num) +
                  (slotmem->desc.num * sizeof(char)) + AP_UNSIGNEDINT_OFFSET;
         apr_file_write(fp, slotmem->persist, &nbytes);