From bbc1e878f5029246c02d893921f05975e49de026 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 18 Sep 2012 10:59:20 +0000 Subject: [PATCH] Add in new type CLEARINUSE which allows the inuse table to be cleared upon storage. This may be expected/wanted/required by some applications git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1387088 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/mod_slotmem_shm.xml | 6 +++--- include/ap_slotmem.h | 10 +++++++--- modules/slotmem/mod_slotmem_shm.c | 27 +++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/docs/manual/mod/mod_slotmem_shm.xml b/docs/manual/mod/mod_slotmem_shm.xml index e129970f16..f27d156ba9 100644 --- a/docs/manual/mod/mod_slotmem_shm.xml +++ b/docs/manual/mod/mod_slotmem_shm.xml @@ -51,11 +51,11 @@
call the callback on all worker slots
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)
-
create a new slotmem with each item size is item_size. name is the filename for the persistent store of - the shared memory. Values are: +
create a new slotmem with each item size is item_size. name is used to generate a filename for the persistent store of + the shared memory if configured. Values are:
"none"
-
Does not persist shared memory in file.
+
Anonymous shared memory and no persistent store
"file-name"
[DefaultRuntimeDir]/file-name
"/absolute-file-name"
diff --git a/include/ap_slotmem.h b/include/ap_slotmem.h index 229aa713f4..b9c810366d 100644 --- a/include/ap_slotmem.h +++ b/include/ap_slotmem.h @@ -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; diff --git a/modules/slotmem/mod_slotmem_shm.c b/modules/slotmem/mod_slotmem_shm.c index f29aefad2d..e5be2448c4 100644 --- a/modules/slotmem/mod_slotmem_shm.c +++ b/modules/slotmem/mod_slotmem_shm.c @@ -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 { @@ -152,6 +153,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; @@ -175,6 +195,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; /* XXX: Error handling */ -- 2.40.0