<dt>apr_size_t slot_size(ap_slotmem_instance_t *s)</dt>
<dd>return the total data size, in bytes, of a slot in the segment</dd>
- <dt>apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
+ <dt>apr_status_t grab(ap_slotmem_instance_t *s, unsigned int *item_id);</dt>
<dd>grab or allocate a slot and mark as in-use (does not do any data copying)</dd>
- <dt>apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
+ <dt>apr_status_t fgrab(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
+ <dd>forced grab or allocate a slot and mark as in-use (does not do any data copying)</dd>
+
+ <dt>apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
<dd>release or free a slot and mark as not in-use (does not do any data copying)</dd>
</dl>
<dt>apr_size_t slot_size(ap_slotmem_instance_t *s)</dt>
<dd>return the total data size, in bytes, of a slot in the segment</dd>
- <dt>apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
+ <dt>apr_status_t grab(ap_slotmem_instance_t *s, unsigned int *item_id);</dt>
<dd>grab or allocate a slot and mark as in-use (does not do any data copying)</dd>
+ <dt>apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
+ <dd>forced grab or allocate a slot and mark as in-use (does not do any data copying)</dd>
+
<dt>apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);</dt>
<dd>release or free a slot and mark as not in-use (does not do any data copying)</dd>
</dl>
* @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;
if (!score)
return APR_ENOSHMAVAIL;
if (id >= score->num)
- return APR_ENOSHMAVAIL;
+ return APR_EINVAL;
ptr = (char *)score->base + score->size * id;
if (!ptr)
}
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);
}
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);
}
}
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;
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;
&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,
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)
{
&slotmem_num_free_slots,
&slotmem_slot_size,
&slotmem_grab,
- &slotmem_release
+ &slotmem_release,
+ &slotmem_fgrab
};
/* make the storage usuable from outside */