]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Add in draft grab/return (alloc/free)... not in API yet.
authorJim Jagielski <jim@apache.org>
Wed, 13 May 2009 18:27:04 +0000 (18:27 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 13 May 2009 18:27:04 +0000 (18:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@774473 13f79535-47bb-0310-9956-ffa450edef68

modules/mem/mod_sharedmem.c

index f66eff8e4f25e0138e5a9d8dc05d2de29d44a5e3..ed1d704dee4c8e8ce898ef840c722861ea5f7e3e 100644 (file)
@@ -48,7 +48,7 @@ struct ap_slotmem_t {
     apr_pool_t           *gpool;      /* per segment global pool */
     apr_global_mutex_t   *smutex;     /* mutex */
     struct ap_slotmem_t  *next;       /* location of next allocated segment */
-    char                 *inuse;      /* is-use flag table*/
+    unsigned int         *inuse;      /* is-use flag table*/
 };
 
 
@@ -449,8 +449,12 @@ static apr_status_t slotmem_get(ap_slotmem_t *slot, unsigned int id, unsigned ch
 {
 
     void *ptr;
+    char *inuse = (slot->base + (slot->size * slot->num));
     apr_status_t ret;
 
+    if (!inuse[id]) {
+        return APR_ENOSHMAVAIL;
+    }
     ret = slotmem_mem(slot, id, &ptr);
     if (ret != APR_SUCCESS) {
         return ret;
@@ -463,17 +467,17 @@ static apr_status_t slotmem_put(ap_slotmem_t *slot, unsigned int id, unsigned ch
 {
 
     void *ptr;
-    char *inuse;
+    char *inuse = (slot->base + (slot->size * slot->num));
     apr_status_t ret;
 
+    if (!inuse[id]) {
+        return APR_ENOSHMAVAIL;
+    }
     ret = slotmem_mem(slot, id, &ptr);
     if (ret != APR_SUCCESS) {
         return ret;
     }
     memcpy(ptr, src, src_len); /* bounds check? */
-    /* We know the id fit it */
-    inuse = (slot->base + (slot->size * slot->num));
-    inuse[id] = 1;
     return APR_SUCCESS;
 }
 
@@ -487,6 +491,53 @@ static apr_size_t slotmem_slot_size(ap_slotmem_t *slot)
     return slot->size;
 }
 
+static apr_status_t slotmem_grab(ap_slotmem_t *slot, unsigned int *id)
+{
+
+    unsigned int i;
+    char *inuse;
+
+    if (!slot) {
+        return APR_ENOSHMAVAIL;
+    }
+    inuse = (slot->base + (slot->size * slot->num));
+
+    SLOTMEM_LOCK(slot->smutex);
+    for (i = 0; i < slot->num; i++, inuse++) {
+        if (!*inuse) {
+            break;
+        }
+    }
+    if (i >= slot->num) {
+        SLOTMEM_UNLOCK(slot->smutex);
+        return APR_ENOSHMAVAIL;
+    }
+    *inuse = 1;
+    *id = i;
+    SLOTMEM_UNLOCK(slot->smutex);
+    return APR_SUCCESS;
+}
+
+static apr_status_t slotmem_return(ap_slotmem_t *slot, unsigned int id)
+{
+
+    char *inuse;
+
+    if (!slot) {
+        return APR_ENOSHMAVAIL;
+    }
+    inuse = (slot->base + (slot->size * slot->num));
+
+    SLOTMEM_LOCK(slot->smutex);
+    if (!inuse[id]) {
+        SLOTMEM_UNLOCK(slot->smutex);
+        return APR_ENOSHMAVAIL;
+    }
+    inuse[id] = 0;
+    SLOTMEM_UNLOCK(slot->smutex);
+    return APR_SUCCESS;
+}
+
 static const ap_slotmem_storage_method storage = {
     "sharedmem",
     &slotmem_do,