From ddd4d2000907421b2d3dd73d7723f5a3132d8258 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 30 Dec 2008 17:08:24 +0000 Subject: [PATCH] And complete the API changes... git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@730181 13f79535-47bb-0310-9956-ffa450edef68 --- modules/mem/mod_slotmem.h | 87 ++++++++++++++++++++++++--- modules/mem/providers/mod_plainmem.c | 11 +--- modules/mem/providers/mod_sharedmem.c | 32 +++++----- 3 files changed, 97 insertions(+), 33 deletions(-) diff --git a/modules/mem/mod_slotmem.h b/modules/mem/mod_slotmem.h index ee32a93afc..a26a244249 100644 --- a/modules/mem/mod_slotmem.h +++ b/modules/mem/mod_slotmem.h @@ -74,7 +74,7 @@ struct ap_slotmem { */ 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. @@ -83,7 +83,7 @@ struct slotmem_storage_method { * @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. @@ -95,7 +95,7 @@ AP_DECLARE(apr_status_t) (* slotmem)(ap_slotmem_t *s, ap_slotmem_callback_fn_t * * @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. @@ -107,7 +107,7 @@ AP_DECLARE(apr_status_t) (* ap_slotmem_create)(ap_slotmem_t **new, const char *n * @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. @@ -115,23 +115,94 @@ AP_DECLARE(apr_status_t) (* ap_slotmem_attach)(ap_slotmem_t **new, const char *n * @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*/ diff --git a/modules/mem/providers/mod_plainmem.c b/modules/mem/providers/mod_plainmem.c index 91616f202c..4adc063256 100644 --- a/modules/mem/providers/mod_plainmem.c +++ b/modules/mem/providers/mod_plainmem.c @@ -18,15 +18,7 @@ * This one uses plain memory. */ -#include "slotmem.h" - -struct ap_slotmem { - char *name; - void *base; - apr_size_t size; - int num; - struct ap_slotmem *next; -}; +#include "mod_slotmem.h" /* global pool and list of slotmem we are handling */ static struct ap_slotmem *globallistmem = NULL; @@ -167,6 +159,7 @@ static int pre_config(apr_pool_t *p, apr_pool_t *plog, static void ap_plainmem_register_hook(apr_pool_t *p) { + static const char * const prePos[] = { "mod_slotmem.c", NULL }; ap_register_provider(p, SLOTMEM_STORAGE, "plain", "0", &storage); ap_hook_pre_config(pre_config, NULL, NULL, APR_HOOK_MIDDLE); } diff --git a/modules/mem/providers/mod_sharedmem.c b/modules/mem/providers/mod_sharedmem.c index 0dcecf8026..ff66dc89ac 100644 --- a/modules/mem/providers/mod_sharedmem.c +++ b/modules/mem/providers/mod_sharedmem.c @@ -18,7 +18,7 @@ * This one uses shared memory. */ -#include "slotmem.h" +#include "mod_slotmem.h" /* The description of the slots to reuse the slotmem */ struct sharedslotdesc { @@ -123,7 +123,7 @@ static apr_status_t cleanup_slotmem(void *param) 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; @@ -139,7 +139,7 @@ static apr_status_t ap_slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *f } 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; @@ -240,7 +240,7 @@ static apr_status_t ap_slotmem_create(ap_slotmem_t **new, const char *name, apr_ *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; @@ -313,7 +313,7 @@ static apr_status_t ap_slotmem_attach(ap_slotmem_t **new, const char *name, apr_ *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; @@ -333,27 +333,27 @@ static apr_status_t ap_slotmem_mem(ap_slotmem_t *slot, int id, void **mem) 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); } @@ -466,7 +466,7 @@ static void child_init(apr_pool_t *p, server_rec *s) 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); -- 2.40.0