*/
typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool);
-struct slotmem_storage_method {
+struct ap_slotmem_storage_method {
/**
* call the callback on all worker slots
* @param s ap_slotmem_t to use.
* @param pool is pool used to create scoreboard
* @return APR_SUCCESS if all went well
*/
-AP_DECLARE(apr_status_t) (* slotmem)(ap_slotmem_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool);
+apr_status_t (* slotmem_do)(ap_slotmem_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool);
/**
* create a new slotmem with each item size is item_size.
* @param pool is pool used to create scoreboard
* @return APR_SUCCESS if all went well
*/
-AP_DECLARE(apr_status_t) (* ap_slotmem_create)(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool);
+apr_status_t (* slotmem_create)(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool);
/**
* attach to an existing slotmem.
* @param pool is pool to memory allocate.
* @return APR_SUCCESS if all went well
*/
-AP_DECLARE(apr_status_t) (* ap_slotmem_attach)(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool);
+apr_status_t (* slotmem_attach)(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool);
/**
* get the memory associated with this worker slot.
* @param s ap_slotmem_t to use.
* @param mem address to store the pointer to the slot
* @return APR_SUCCESS if all went well
*/
-AP_DECLARE(apr_status_t) (* ap_slotmem_mem)(ap_slotmem_t *s, int item_id, void**mem);
+apr_status_t (* slotmem_mem)(ap_slotmem_t *s, int item_id, void**mem);
/**
* lock the memory segment
* NOTE: All slots share the same mutex
* @param s ap_slotmem_t to use
* @return APR_SUCCESS if all went well
*/
-AP_DECLARE(apr_status_t) (* ap_slotmem_lock)(ap_slotmem_t *s);
+apr_status_t (* slotmem_lock)(ap_slotmem_t *s);
/**
* unlock the memory segment
* NOTE: All slots share the same mutex
* @param s ap_slotmem_t to use.
* @return APR_SUCCESS if all went well
*/
-AP_DECLARE(apr_status_t) (* ap_slotmem_unlock)(ap_slotmem_t *s);
+apr_status_t (* slotmem_unlock)(ap_slotmem_t *s);
};
-typedef struct slotmem_storage_method slotmem_storage_method;
+typedef struct ap_slotmem_storage_method ap_slotmem_storage_method;
+
+/*
+ * mod_slotmem externals exposed to the outside world.
+ * Thus the provider nature of mod_slotmem is somewhat insulated
+ * from the end user but can still be used directed if need
+ * be. The rationale is to make it easier for additional
+ * memory providers to be provided and having a single
+ * simple interface for all
+ */
+/**
+ * obtain the provider method desired
+ * @param provider is name of the provider to use
+ * @return pointer to provider or NULL
+ */
+AP_DECLARE(ap_slotmem_storage_method *) ap_slotmem_method(const char *provider);
+/**
+ * call the callback on all worker slots
+ * @param sm ap_slotmem_storage_method provider obtained
+ * @param s ap_slotmem_t to use.
+ * @param funct callback function to call for each element.
+ * @param data parameter for the callback function.
+ * @param pool is pool used to create scoreboard
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_do(ap_slotmem_storage_method *sm, ap_slotmem_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool);
+
+/**
+ * create a new slotmem with each item size is item_size.
+ * This would create shared memory, basically.
+ * @param pointer to store the address of the scoreboard.
+ * @param name is a key used for debugging and in mod_status output or allow another process to share this space.
+ * @param item_size size of each item
+ * @param item_num number of item to create.
+ * @param pool is pool used to create scoreboard
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_create(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool);
+
+/**
+ * attach to an existing slotmem.
+ * This would attach to shared memory, basically.
+ * @param pointer to store the address of the scoreboard.
+ * @param name is a key used for debugging and in mod_status output or allow another process to share this space.
+ * @param item_size size of each item
+ * @param item_num max number of item.
+ * @param pool is pool to memory allocate.
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_attach(ap_slotmem_storage_method *sm, ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool);
+/**
+ * get the memory associated with this worker slot.
+ * @param s ap_slotmem_t to use.
+ * @param item_id item to return for 0 to item_num
+ * @param mem address to store the pointer to the slot
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_mem(ap_slotmem_storage_method *sm, ap_slotmem_t *s, int item_id, void**mem);
+/**
+ * lock the memory segment
+ * NOTE: All slots share the same mutex
+ * @param s ap_slotmem_t to use
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_lock(ap_slotmem_storage_method *sm, ap_slotmem_t *s);
+/**
+ * unlock the memory segment
+ * NOTE: All slots share the same mutex
+ * @param s ap_slotmem_t to use.
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_unlock(ap_slotmem_storage_method *sm, ap_slotmem_t *s);
#endif /*SLOTMEM_H*/
* This one uses shared memory.
*/
-#include "slotmem.h"
+#include "mod_slotmem.h"
/* The description of the slots to reuse the slotmem */
struct sharedslotdesc {
return APR_SUCCESS;
}
-static apr_status_t ap_slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool)
+static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool)
{
int i;
void *ptr;
}
return APR_SUCCESS;
}
-static apr_status_t ap_slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool)
+static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size, int item_num, apr_pool_t *pool)
{
/* void *slotmem = NULL; */
void *ptr;
*new = res;
return APR_SUCCESS;
}
-static apr_status_t ap_slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool)
+static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size, int *item_num, apr_pool_t *pool)
{
/* void *slotmem = NULL; */
void *ptr;
*item_num = desc.item_num;
return APR_SUCCESS;
}
-static apr_status_t ap_slotmem_mem(ap_slotmem_t *slot, int id, void **mem)
+static apr_status_t slotmem_mem(ap_slotmem_t *slot, int id, void **mem)
{
void *ptr;
return APR_SUCCESS;
}
-static apr_status_t ap_slotmem_lock(ap_slotmem_t *slot)
+static apr_status_t slotmem_lock(ap_slotmem_t *slot)
{
return (apr_global_mutex_lock(slot->smutex));
}
-static apr_status_t ap_slotmem_unlock(ap_slotmem_t *slot)
+static apr_status_t slotmem_unlock(ap_slotmem_t *slot)
{
return (apr_global_mutex_unlock(slot->smutex));
}
-static const slotmem_storage_method storage = {
- &ap_slotmem_do,
- &ap_slotmem_create,
- &ap_slotmem_attach,
- &ap_slotmem_mem,
- &ap_slotmem_lock,
- &ap_slotmem_unlock
+static const ap_slotmem_storage_method storage = {
+ &slotmem_do,
+ &slotmem_create,
+ &slotmem_attach,
+ &slotmem_mem,
+ &slotmem_lock,
+ &slotmem_unlock
};
/* make the storage usuable from outside */
-static const slotmem_storage_method *sharedmem_getstorage(void)
+static const ap_slotmem_storage_method *sharedmem_getstorage(void)
{
return (&storage);
}
static void ap_sharedmem_register_hook(apr_pool_t *p)
{
- const slotmem_storage_method *storage = sharedmem_getstorage();
+ const ap_slotmem_storage_method *storage = sharedmem_getstorage();
ap_register_provider(p, SLOTMEM_STORAGE, "shared", "0", storage);
ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_LAST);
ap_hook_pre_config(pre_config, NULL, NULL, APR_HOOK_MIDDLE);