httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r775265 - /httpd/httpd/trunk/modules/slotmem/mod_slotmem_plain.c
Date Fri, 15 May 2009 17:59:57 GMT
Author: jim
Date: Fri May 15 17:59:57 2009
New Revision: 775265

URL: http://svn.apache.org/viewvc?rev=775265&view=rev
Log:
Add inuse table and grab/release to plainmem slot provider

Modified:
    httpd/httpd/trunk/modules/slotmem/mod_slotmem_plain.c

Modified: httpd/httpd/trunk/modules/slotmem/mod_slotmem_plain.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/slotmem/mod_slotmem_plain.c?rev=775265&r1=775264&r2=775265&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/slotmem/mod_slotmem_plain.c (original)
+++ httpd/httpd/trunk/modules/slotmem/mod_slotmem_plain.c Fri May 15 17:59:57 2009
@@ -20,6 +20,8 @@
 
 #include  "ap_slotmem.h"
 
+#define AP_SLOTMEM_IS_PREGRAB(t) (t->type & AP_SLOTMEM_TYPE_PREGRAB)
+
 struct ap_slotmem_instance_t {
     char                 *name;       /* per segment name */
     void                 *base;       /* data set start */
@@ -40,14 +42,19 @@
 {
     unsigned int i;
     void *ptr;
+    char *inuse;
 
     if (!mem)
         return APR_ENOSHMAVAIL;
 
     ptr = mem->base;
-    for (i = 0; i < mem->num; i++) {
-        ptr = ptr + mem->size;
-        func((void *) ptr, data, pool);
+    inuse = mem->inuse;
+    for (i = 0; i < mem->num; i++, inuse++) {
+        if (!AP_SLOTMEM_IS_PREGRAB(mem) ||
+           (AP_SLOTMEM_IS_PREGRAB(mem) && *inuse)) {
+            func((void *) ptr, data, pool);
+        }
+        ptr += mem->size;
     }
     return APR_SUCCESS;
 }
@@ -56,6 +63,8 @@
 {
     ap_slotmem_instance_t *res;
     ap_slotmem_instance_t *next = globallistmem;
+    apr_size_t basesize = (item_size * item_num);
+
     const char *fname;
 
     if (name) {
@@ -79,7 +88,7 @@
 
     /* create the memory using the gpool */
     res = (ap_slotmem_instance_t *) apr_pcalloc(gpool, sizeof(ap_slotmem_instance_t));
-    res->base = apr_pcalloc(gpool, item_size * item_num);
+    res->base = apr_pcalloc(gpool, basesize + (item_num * sizeof(char)));
     if (!res->base)
         return APR_ENOSHMAVAIL;
 
@@ -89,6 +98,7 @@
     res->num = item_num;
     res->next = NULL;
     res->type = type;
+    res->inuse = res->base + basesize;
     if (globallistmem == NULL)
         globallistmem = res;
     else
@@ -146,10 +156,18 @@
 
 static apr_status_t slotmem_get(ap_slotmem_instance_t *slot, unsigned int id, unsigned char
*dest, apr_size_t dest_len)
 {
-
     void *ptr;
+    char *inuse;
     apr_status_t ret;
 
+    if (!slot) {
+        return APR_ENOSHMAVAIL;
+    }
+
+    inuse = slot->inuse + id;
+    if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) {
+        return APR_NOTFOUND;
+    }
     ret = slotmem_dptr(slot, id, &ptr);
     if (ret != APR_SUCCESS) {
         return ret;
@@ -160,10 +178,18 @@
 
 static apr_status_t slotmem_put(ap_slotmem_instance_t *slot, unsigned int id, unsigned char
*src, apr_size_t src_len)
 {
-
     void *ptr;
+    char *inuse;
     apr_status_t ret;
 
+    if (!slot) {
+        return APR_ENOSHMAVAIL;
+    }
+
+    inuse = slot->inuse + id;
+    if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) {
+        return APR_NOTFOUND;
+    }
     ret = slotmem_dptr(slot, id, &ptr);
     if (ret != APR_SUCCESS) {
         return ret;
@@ -182,6 +208,51 @@
     return slot->size;
 }
 
+/*
+ * XXXX: if !AP_SLOTMEM_IS_PREGRAB, then still worry about
+ *       inuse for grab and return?
+ */
+static apr_status_t slotmem_grab(ap_slotmem_instance_t *slot, unsigned int *id)
+{
+    unsigned int i;
+    char *inuse;
+
+    if (!slot) {
+        return APR_ENOSHMAVAIL;
+    }
+
+    inuse = slot->inuse;
+
+    for (i = 0; i < slot->num; i++, inuse++) {
+        if (!*inuse) {
+            break;
+        }
+    }
+    if (i >= slot->num) {
+        return APR_ENOSHMAVAIL;
+    }
+    *inuse = 1;
+    *id = i;
+    return APR_SUCCESS;
+}
+
+static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id)
+{
+    char *inuse;
+
+    if (!slot) {
+        return APR_ENOSHMAVAIL;
+    }
+
+    inuse = slot->inuse;
+
+    if (id >= slot->num || !inuse[id] ) {
+        return APR_NOTFOUND;
+    }
+    inuse[id] = 0;
+    return APR_SUCCESS;
+}
+
 static const ap_slotmem_provider_t storage = {
     "plainmem",
     &slotmem_do,



Mime
View raw message