typedef unsigned int ap_slotmem_type_t;
+/*
+ * AP_SLOTMEM_TYPE_PERSIST: For transitory providers, persist
+ * the data on the file-system
+ *
+ * AP_SLOTMEM_TYPE_NOTMPSAFE:
+ *
+ * AP_SLOTMEM_TYPE_PREALLOC: Access to slots require they be grabbed 1st
+ */
#define AP_SLOTMEM_TYPE_PERSIST (1 << 0)
#define AP_SLOTMEM_TYPE_NOTMPSAFE (1 << 1)
+#define AP_SLOTMEM_TYPE_PREGRAB (1 << 2)
typedef struct ap_slotmem_instance_t ap_slotmem_instance_t;
#endif
#endif
+#define AP_SLOTMEM_IS_PREGRAB(t) (t->type & AP_SLOTMEM_TYPE_PREGRAB)
+
struct ap_slotmem_instance_t {
char *name; /* per segment name */
void *shm; /* ptr to memory segment (apr_shm_t *) */
apr_size_t size; /* size of each memory slot */
unsigned int num; /* number of mem slots */
apr_pool_t *gpool; /* per segment global pool */
- struct ap_slotmem_instance_t *next; /* location of next allocated segment */
char *inuse; /* in-use flag table*/
+ ap_slotmem_type_t type; /* type-specific flags */
+ struct ap_slotmem_instance_t *next; /* location of next allocated segment */
};
struct sharedslotdesc {
apr_size_t item_size;
unsigned int item_num;
+ ap_slotmem_type_t type;
};
/*
ptr = mem->base;
inuse = mem->inuse;
for (i = 0; i < mem->num; i++, inuse++) {
- if (*inuse) {
+ if (!AP_SLOTMEM_IS_PREGRAB(mem) ||
+ (AP_SLOTMEM_IS_PREGRAB(mem) && *inuse)) {
func((void *) ptr, data, pool);
}
ptr += mem->size;
ptr = apr_shm_baseaddr_get(shm);
desc.item_size = item_size;
desc.item_num = item_num;
+ desc.type = type;
memcpy(ptr, &desc, sizeof(desc));
ptr = ptr + sizeof(desc);
memset(ptr, 0, dsize);
res->base = ptr;
res->size = item_size;
res->num = item_num;
+ res->type = type;
res->gpool = gpool;
res->next = NULL;
res->inuse = ptr + basesize;
res->base = ptr;
res->size = desc.item_size;
res->num = desc.item_num;
+ res->type = desc.type;
res->gpool = gpool;
res->inuse = ptr + (desc.item_size * desc.item_num);
res->next = NULL;
static apr_status_t slotmem_mem(ap_slotmem_instance_t *slot, unsigned int id, void **mem)
{
-
void *ptr;
if (!slot) {
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;
return APR_ENOSHMAVAIL;
}
- inuse = slot->inuse;
- if (id >= slot->num || !inuse[id] ) {
+ inuse = slot->inuse + id;
+ if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) {
return APR_NOTFOUND;
}
ret = slotmem_mem(slot, id, &ptr);
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;
return APR_ENOSHMAVAIL;
}
- inuse = slot->inuse;
- if (id >= slot->num || !inuse[id] ) {
+ inuse = slot->inuse + id;
+ if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) {
return APR_NOTFOUND;
}
ret = slotmem_mem(slot, id, &ptr);
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;
static apr_status_t slotmem_return(ap_slotmem_instance_t *slot, unsigned int id)
{
-
char *inuse;
if (!slot) {