httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r773977 - in /httpd/httpd/trunk: include/ap_slotmem.h modules/mem/mod_plainmem.c modules/mem/mod_sharedmem.c server/slotmem.c
Date Tue, 12 May 2009 16:55:17 GMT
Author: jim
Date: Tue May 12 16:55:17 2009
New Revision: 773977

URL: http://svn.apache.org/viewvc?rev=773977&view=rev
Log:
If we have a mutex, we should use it whenever we create a
shared mem segment. This allows safe segment creation post
child-init

Modified:
    httpd/httpd/trunk/include/ap_slotmem.h
    httpd/httpd/trunk/modules/mem/mod_plainmem.c
    httpd/httpd/trunk/modules/mem/mod_sharedmem.c
    httpd/httpd/trunk/server/slotmem.c

Modified: httpd/httpd/trunk/include/ap_slotmem.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_slotmem.h?rev=773977&r1=773976&r2=773977&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_slotmem.h (original)
+++ httpd/httpd/trunk/include/ap_slotmem.h Tue May 12 16:55:17 2009
@@ -126,6 +126,18 @@
      * @return APR_SUCCESS if all went well
      */
     apr_status_t (* slotmem_put)(ap_slotmem_t *slot, unsigned int item_id, unsigned char
*src, apr_size_t src_len);
+    /**
+     * return number of slots allocated for this entry.
+     * @param s ap_slotmem_t to use.
+     * @return number of slots
+     */
+    unsigned int (* slotmem_num_slots)(ap_slotmem_t *s);
+    /**
+     * return slot size allocated for this entry.
+     * @param s ap_slotmem_t to use.
+     * @return size of slot
+     */
+    apr_size_t (* slotmem_slot_size)(ap_slotmem_t *s);
 };
 
 typedef struct ap_slotmem_storage_method ap_slotmem_storage_method;
@@ -214,5 +226,19 @@
  * @return APR_SUCCESS if all went well
  */
 AP_DECLARE(apr_status_t) ap_slotmem_put(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned
int item_id, unsigned char *src, apr_size_t src_len);
+/**
+ * return number of slots allocated for this entry.
+ * @param sm ap_slotmem_storage_method provider obtained
+ * @param s ap_slotmem_t to use.
+ * @return number of slots
+ */
+AP_DECLARE(unsigned int) ap_slotmem_num_slots(ap_slotmem_storage_method *sm, ap_slotmem_t
*s);
+/**
+ * return slot size allocated for this entry.
+ * @param sm ap_slotmem_storage_method provider obtained
+ * @param s ap_slotmem_t to use.
+ * @return size of slot
+ */
+AP_DECLARE(apr_size_t) ap_slotmem_slot_size(ap_slotmem_storage_method *sm, ap_slotmem_t *s);
 
 #endif /*SLOTMEM_H*/

Modified: httpd/httpd/trunk/modules/mem/mod_plainmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_plainmem.c?rev=773977&r1=773976&r2=773977&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_plainmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_plainmem.c Tue May 12 16:55:17 2009
@@ -177,6 +177,16 @@
     return APR_SUCCESS;
 }
 
+static unsigned int slotmem_num_slots(ap_slotmem_t *slot)
+{
+    return slot->num;
+}
+
+static apr_size_t slotmem_slot_size(ap_slotmem_t *slot)
+{
+    return slot->size;
+}
+
 static const ap_slotmem_storage_method storage = {
     "plainmem",
     &slotmem_do,
@@ -184,7 +194,9 @@
     &slotmem_attach,
     &slotmem_mem,
     &slotmem_get,
-    &slotmem_put
+    &slotmem_put,
+    &slotmem_num_slots,
+    &slotmem_slot_size
 };
 
 static int pre_config(apr_pool_t *p, apr_pool_t *plog,

Modified: httpd/httpd/trunk/modules/mem/mod_sharedmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_sharedmem.c?rev=773977&r1=773976&r2=773977&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_sharedmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_sharedmem.c Tue May 12 16:55:17 2009
@@ -60,8 +60,18 @@
 /* global pool and list of slotmem we are handling */
 static struct ap_slotmem_t *globallistmem = NULL;
 static apr_pool_t *gpool = NULL;
-static apr_global_mutex_t *smutex;
-static const char *mutex_fname;
+static apr_global_mutex_t *smutex = NULL;
+static const char *mutex_fname = NULL;
+
+#define SLOTMEM_LOCK(s) do {      \
+    if (s)                        \
+        apr_global_mutex_lock(s); \
+} while (0)
+
+#define SLOTMEM_UNLOCK(s) do {      \
+    if (s)                          \
+        apr_global_mutex_unlock(s); \
+} while (0)
 
 /* apr:shmem/unix/shm.c */
 static apr_status_t unixd_set_shm_perms(const char *fname)
@@ -201,10 +211,12 @@
     }
 
     ptr = mem->base;
+    SLOTMEM_LOCK(mem->smutex);
     for (i = 0; i < mem->num; i++) {
         ptr = ptr + mem->size;
         func((void *) ptr, data, pool);
     }
+    SLOTMEM_UNLOCK(mem->smutex);
     return APR_SUCCESS;
 }
 
@@ -270,6 +282,7 @@
         ptr = ptr + sizeof(desc);
     }
     else {
+        SLOTMEM_LOCK(smutex);
         if (name && name[0] != ':') {
             apr_shm_remove(fname, gpool);
             rv = apr_shm_create(&shm, item_size * item_num + sizeof(struct sharedslotdesc),
fname, gpool);
@@ -277,6 +290,7 @@
         else {
             rv = apr_shm_create(&shm, item_size * item_num + sizeof(struct sharedslotdesc),
NULL, gpool);
         }
+        SLOTMEM_UNLOCK(smutex);
         if (rv != APR_SUCCESS) {
             return rv;
         }
@@ -444,6 +458,16 @@
     return APR_SUCCESS;
 }
 
+static unsigned int slotmem_num_slots(ap_slotmem_t *slot)
+{
+    return slot->num;
+}
+
+static apr_size_t slotmem_slot_size(ap_slotmem_t *slot)
+{
+    return slot->size;
+}
+
 static const ap_slotmem_storage_method storage = {
     "sharedmem",
     &slotmem_do,
@@ -451,7 +475,9 @@
     &slotmem_attach,
     &slotmem_mem,
     &slotmem_get,
-    &slotmem_put
+    &slotmem_put,
+    &slotmem_num_slots,
+    &slotmem_slot_size
 };
 
 /* make the storage usuable from outside */

Modified: httpd/httpd/trunk/server/slotmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/slotmem.c?rev=773977&r1=773976&r2=773977&view=diff
==============================================================================
--- httpd/httpd/trunk/server/slotmem.c (original)
+++ httpd/httpd/trunk/server/slotmem.c Tue May 12 16:55:17 2009
@@ -76,6 +76,16 @@
     return (sm->slotmem_put(s, item_id, src, src_len));
 }
 
+AP_DECLARE(unsigned int) ap_slotmem_num_slots(ap_slotmem_storage_method *sm, ap_slotmem_t
*s)
+{
+    return (sm->slotmem_num_slots(s));
+}
+
+AP_DECLARE(apr_size_t) ap_slotmem_slot_size(ap_slotmem_storage_method *sm, ap_slotmem_t *s)
+{
+    return (sm->slotmem_slot_size(s));
+}
+
 module AP_MODULE_DECLARE_DATA slotmem_module = {
     STANDARD20_MODULE_STUFF,
     NULL,                       /* create per-directory config structure */



Mime
View raw message