From 6e77cfce5144e61d1e9b62cad049bd9cec1ceb50 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Mon, 17 Sep 2012 22:26:28 +0000 Subject: [PATCH] Allow for a forced grab of a slotmem slot. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1386880 13f79535-47bb-0310-9956-ffa450edef68 --- docs/log-message-tags/next-number | 2 +- docs/manual/mod/mod_slotmem_plain.xml | 7 +++-- docs/manual/mod/mod_slotmem_shm.xml | 5 +++- include/ap_slotmem.h | 7 +++++ modules/slotmem/mod_slotmem_plain.c | 40 +++++++++++++++++++++++---- modules/slotmem/mod_slotmem_shm.c | 27 +++++++++++++++++- 6 files changed, 77 insertions(+), 11 deletions(-) diff --git a/docs/log-message-tags/next-number b/docs/log-message-tags/next-number index d61563f9298..fd75012648e 100644 --- a/docs/log-message-tags/next-number +++ b/docs/log-message-tags/next-number @@ -1 +1 @@ -2336 +2337 diff --git a/docs/manual/mod/mod_slotmem_plain.xml b/docs/manual/mod/mod_slotmem_plain.xml index d5f9d232c45..61603f189f5 100644 --- a/docs/manual/mod/mod_slotmem_plain.xml +++ b/docs/manual/mod/mod_slotmem_plain.xml @@ -67,10 +67,13 @@
apr_size_t slot_size(ap_slotmem_instance_t *s)
return the total data size, in bytes, of a slot in the segment
-
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);
+
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int *item_id);
grab or allocate a slot and mark as in-use (does not do any data copying)
-
apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);
+
apr_status_t fgrab(ap_slotmem_instance_t *s, unsigned int item_id);
+
forced grab or allocate a slot and mark as in-use (does not do any data copying)
+ +
apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);
release or free a slot and mark as not in-use (does not do any data copying)
diff --git a/docs/manual/mod/mod_slotmem_shm.xml b/docs/manual/mod/mod_slotmem_shm.xml index cee9a8e4ebf..e129970f167 100644 --- a/docs/manual/mod/mod_slotmem_shm.xml +++ b/docs/manual/mod/mod_slotmem_shm.xml @@ -80,9 +80,12 @@
apr_size_t slot_size(ap_slotmem_instance_t *s)
return the total data size, in bytes, of a slot in the segment
-
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);
+
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int *item_id);
grab or allocate a slot and mark as in-use (does not do any data copying)
+
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);
+
forced grab or allocate a slot and mark as in-use (does not do any data copying)
+
apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);
release or free a slot and mark as not in-use (does not do any data copying)
diff --git a/include/ap_slotmem.h b/include/ap_slotmem.h index 496f455e69b..229aa713f43 100644 --- a/include/ap_slotmem.h +++ b/include/ap_slotmem.h @@ -175,6 +175,13 @@ struct ap_slotmem_provider_t { * @return APR_SUCCESS if all went well */ apr_status_t (* release)(ap_slotmem_instance_t *s, unsigned int item_id); + /** + * forced grab (or alloc) a slot associated with this item_id + * @param s ap_slotmem_instance_t to use. + * @param item_id to the specified slot id and marked as in-use + * @return APR_SUCCESS if all went well + */ + apr_status_t (* fgrab)(ap_slotmem_instance_t *s, unsigned int item_id); }; typedef struct ap_slotmem_provider_t ap_slotmem_provider_t; diff --git a/modules/slotmem/mod_slotmem_plain.c b/modules/slotmem/mod_slotmem_plain.c index dc62f46f85b..cc33bfd654c 100644 --- a/modules/slotmem/mod_slotmem_plain.c +++ b/modules/slotmem/mod_slotmem_plain.c @@ -154,7 +154,7 @@ static apr_status_t slotmem_dptr(ap_slotmem_instance_t *score, unsigned int id, if (!score) return APR_ENOSHMAVAIL; if (id >= score->num) - return APR_ENOSHMAVAIL; + return APR_EINVAL; ptr = (char *)score->base + score->size * id; if (!ptr) @@ -174,7 +174,10 @@ static apr_status_t slotmem_get(ap_slotmem_instance_t *slot, unsigned int id, un } inuse = slot->inuse + id; - if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { + if (id >= slot->num) { + return APR_EINVAL; + } + if (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse) { return APR_NOTFOUND; } ret = slotmem_dptr(slot, id, &ptr); @@ -197,7 +200,10 @@ static apr_status_t slotmem_put(ap_slotmem_instance_t *slot, unsigned int id, un } inuse = slot->inuse + id; - if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { + if (id >= slot->num) { + return APR_EINVAL; + } + if (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse) { return APR_NOTFOUND; } ret = slotmem_dptr(slot, id, &ptr); @@ -251,13 +257,31 @@ static apr_status_t slotmem_grab(ap_slotmem_instance_t *slot, unsigned int *id) } } if (i >= slot->num) { - return APR_ENOSHMAVAIL; + return APR_EINVAL; } *inuse = 1; *id = i; return APR_SUCCESS; } +*/ +static apr_status_t slotmem_fgrab(ap_slotmem_instance_t *slot, unsigned int id) +{ + unsigned int i; + char *inuse; + + if (!slot) { + return APR_ENOSHMAVAIL; + } + + if (id >= slot->num) { + return APR_EINVAL; + } + inuse = slot->inuse + id; + *inuse = 1; + return APR_SUCCESS; +} + static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id) { char *inuse; @@ -268,7 +292,10 @@ static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id inuse = slot->inuse; - if (id >= slot->num || !inuse[id] ) { + if (id >= slot->num) { + return APR_EINVAL; + } + if (!inuse[id] ) { return APR_NOTFOUND; } inuse[id] = 0; @@ -287,7 +314,8 @@ static const ap_slotmem_provider_t storage = { &slotmem_num_free_slots, &slotmem_slot_size, &slotmem_grab, - &slotmem_release + &slotmem_release, + &slotmem_fgrab }; static int pre_config(apr_pool_t *p, apr_pool_t *plog, diff --git a/modules/slotmem/mod_slotmem_shm.c b/modules/slotmem/mod_slotmem_shm.c index bdc46ad80e0..651f6336027 100644 --- a/modules/slotmem/mod_slotmem_shm.c +++ b/modules/slotmem/mod_slotmem_shm.c @@ -608,6 +608,30 @@ static apr_status_t slotmem_grab(ap_slotmem_instance_t *slot, unsigned int *id) return APR_SUCCESS; } +static apr_status_t slotmem_fgrab(ap_slotmem_instance_t *slot, unsigned int id) +{ + char *inuse; + + if (!slot) { + return APR_ENOSHMAVAIL; + } + + if (id >= slot->desc.num) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02236) + "slotmem(%s) fgrab failed. Num %u/num_free %u", + slot->name, slotmem_num_slots(slot), + slotmem_num_free_slots(slot)); + return APR_EINVAL; + } + inuse = slot->inuse + id; + + if (!*inuse) { + *inuse = 1; + (*slot->num_free)--; + } + return APR_SUCCESS; +} + static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id) { @@ -647,7 +671,8 @@ static const ap_slotmem_provider_t storage = { &slotmem_num_free_slots, &slotmem_slot_size, &slotmem_grab, - &slotmem_release + &slotmem_release, + &slotmem_fgrab }; /* make the storage usuable from outside */ -- 2.47.2