httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r730133 - in /httpd/httpd/trunk/modules/mem: mod_plainmem.c mod_sharedmem.c slotmem.h
Date Tue, 30 Dec 2008 13:59:17 GMT
Author: jim
Date: Tue Dec 30 05:59:17 2008
New Revision: 730133

URL: http://svn.apache.org/viewvc?rev=730133&view=rev
Log:
Move desc of slotmem type to be generic enough so can be
shared among all memory providers.

Modified:
    httpd/httpd/trunk/modules/mem/mod_plainmem.c
    httpd/httpd/trunk/modules/mem/mod_sharedmem.c
    httpd/httpd/trunk/modules/mem/slotmem.h

Modified: httpd/httpd/trunk/modules/mem/mod_plainmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_plainmem.c?rev=730133&r1=730132&r2=730133&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_plainmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_plainmem.c Tue Dec 30 05:59:17 2008
@@ -30,7 +30,7 @@
 
 /* global pool and list of slotmem we are handling */
 static struct ap_slotmem *globallistmem = NULL;
-static apr_pool_t *globalpool = NULL;
+static apr_pool_t *gpool = NULL;
 
 static apr_status_t ap_slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void
*data, apr_pool_t *pool)
 {
@@ -78,14 +78,14 @@
     else
 	fname = "anonymous";
 
-    /* create the memory using the globalpool */
-    res = (ap_slotmem_t *) apr_pcalloc(globalpool, sizeof(ap_slotmem_t));
-    res->base = apr_pcalloc(globalpool, item_size * item_num);
+    /* create the memory using the gpool */
+    res = (ap_slotmem_t *) apr_pcalloc(gpool, sizeof(ap_slotmem_t));
+    res->base = apr_pcalloc(gpool, item_size * item_num);
     if (!res->base)
 	return APR_ENOSHMAVAIL;
 
     /* For the chained slotmem stuff */
-    res->name = apr_pstrdup(globalpool, fname);
+    res->name = apr_pstrdup(gpool, fname);
     res->size = item_size;
     res->num = item_num;
     res->next = NULL;
@@ -161,7 +161,7 @@
 static int pre_config(apr_pool_t *p, apr_pool_t *plog,
 		          apr_pool_t *ptemp)
 {
-    globalpool = p;
+    gpool = p;
     return OK;
 }
 

Modified: httpd/httpd/trunk/modules/mem/mod_sharedmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_sharedmem.c?rev=730133&r1=730132&r2=730133&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_sharedmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_sharedmem.c Tue Dec 30 05:59:17 2008
@@ -26,21 +26,10 @@
     int item_num;
 };
 
-struct ap_slotmem {
-    char *name;
-    apr_shm_t *shm;
-    void *base;
-    apr_size_t size;
-    int num;
-    apr_pool_t *globalpool;
-    apr_global_mutex_t *sharedmem_mutex;
-    struct ap_slotmem *next;
-};
-
 /* global pool and list of slotmem we are handling */
 static struct ap_slotmem *globallistmem = NULL;
-static apr_pool_t *globalpool = NULL;
-static apr_global_mutex_t *sharedmem_mutex;
+static apr_pool_t *gpool = NULL;
+static apr_global_mutex_t *smutex;
 static const char *mutex_fname;
 
 /*
@@ -75,12 +64,12 @@
     apr_size_t nbytes;
     const char *storename;
 
-    storename = store_filename(slotmem->globalpool, slotmem->name);
+    storename = store_filename(slotmem->gpool, slotmem->name);
 
-    rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT,
slotmem->globalpool);
+    rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT,
slotmem->gpool);
     if (APR_STATUS_IS_EEXIST(rv)) {
-	apr_file_remove(storename, slotmem->globalpool);
-	rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT,
slotmem->globalpool);
+	apr_file_remove(storename, slotmem->gpool);
+	rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE, APR_OS_DEFAULT,
slotmem->gpool);
     }
     if (rv != APR_SUCCESS) {
 	return;
@@ -123,10 +112,10 @@
 
     if (*mem) {
 	ap_slotmem_t *next = *mem;
-	pool = next->globalpool;
+	pool = next->gpool;
 	while (next) {
 	    store_slotmem(next);
-	    rv = apr_shm_destroy(next->shm);
+	    rv = apr_shm_destroy((apr_shm_t *)next->shm);
 	    next = next->next;
 	}
 	apr_pool_destroy(pool);
@@ -160,7 +149,7 @@
     const char *fname;
     apr_status_t rv;
 
-    if (globalpool == NULL)
+    if (gpool == NULL)
 	return APR_ENOSHMAVAIL;
     if (name) {
 	if (name[0] == ':') {
@@ -190,24 +179,24 @@
     }
 
     /* first try to attach to existing shared memory */
-    res = (ap_slotmem_t *) apr_pcalloc(globalpool, sizeof(ap_slotmem_t));
+    res = (ap_slotmem_t *) apr_pcalloc(gpool, sizeof(ap_slotmem_t));
     if (name && name[0] != ':') {
-	rv = apr_shm_attach(&res->shm, fname, globalpool);
+	rv = apr_shm_attach((apr_shm_t **)&res->shm, fname, gpool);
     }
     else {
 	rv = APR_EINVAL;
     }
     if (rv == APR_SUCCESS) {
 	/* check size */
-	if (apr_shm_size_get(res->shm) != item_size * item_num + sizeof(struct sharedslotdesc))
{
-	    apr_shm_detach(res->shm);
+	if (apr_shm_size_get((apr_shm_t *)res->shm) != item_size * item_num + sizeof(struct sharedslotdesc))
{
+	    apr_shm_detach((apr_shm_t *)res->shm);
 	    res->shm = NULL;
 	    return APR_EINVAL;
 	}
-	ptr = apr_shm_baseaddr_get(res->shm);
+	ptr = apr_shm_baseaddr_get((apr_shm_t *)res->shm);
 	memcpy(&desc, ptr, sizeof(desc));
 	if (desc.item_size != item_size || desc.item_num != item_num) {
-	    apr_shm_detach(res->shm);
+	    apr_shm_detach((apr_shm_t *)res->shm);
 	    res->shm = NULL;
 	    return APR_EINVAL;
 	}
@@ -215,16 +204,16 @@
     }
     else {
 	if (name && name[0] != ':') {
-	    apr_shm_remove(fname, globalpool);
-	    rv = apr_shm_create(&res->shm, item_size * item_num + sizeof(struct sharedslotdesc),
fname, globalpool);
+	    apr_shm_remove(fname, gpool);
+	    rv = apr_shm_create((apr_shm_t **)&res->shm, item_size * item_num + sizeof(struct
sharedslotdesc), fname, gpool);
 	}
 	else {
-	    rv = apr_shm_create(&res->shm, item_size * item_num + sizeof(struct sharedslotdesc),
NULL, globalpool);
+	    rv = apr_shm_create((apr_shm_t **)&res->shm, item_size * item_num + sizeof(struct
sharedslotdesc), NULL, gpool);
 	}
 	if (rv != APR_SUCCESS) {
 	    return rv;
 	}
-	ptr = apr_shm_baseaddr_get(res->shm);
+	ptr = apr_shm_baseaddr_get((apr_shm_t *)res->shm);
 	desc.item_size = item_size;
 	desc.item_num = item_num;
 	memcpy(ptr, &desc, sizeof(desc));
@@ -234,12 +223,12 @@
     }
 
     /* For the chained slotmem stuff */
-    res->name = apr_pstrdup(globalpool, fname);
+    res->name = apr_pstrdup(gpool, fname);
     res->base = ptr;
     res->size = item_size;
     res->num = item_num;
-    res->globalpool = globalpool;
-    res->sharedmem_mutex = sharedmem_mutex;
+    res->gpool = gpool;
+    res->smutex = smutex;
     res->next = NULL;
     if (globallistmem == NULL) {
 	globallistmem = res;
@@ -261,7 +250,7 @@
     const char *fname;
     apr_status_t rv;
 
-    if (globalpool == NULL) {
+    if (gpool == NULL) {
 	return APR_ENOSHMAVAIL;
     }
     if (name) {
@@ -293,24 +282,24 @@
     }
 
     /* first try to attach to existing shared memory */
-    res = (ap_slotmem_t *) apr_pcalloc(globalpool, sizeof(ap_slotmem_t));
-    rv = apr_shm_attach(&res->shm, fname, globalpool);
+    res = (ap_slotmem_t *) apr_pcalloc(gpool, sizeof(ap_slotmem_t));
+    rv = apr_shm_attach((apr_shm_t **)&res->shm, fname, gpool);
     if (rv != APR_SUCCESS) {
 	return rv;
     }
 
     /* Read the description of the slotmem */
-    ptr = apr_shm_baseaddr_get(res->shm);
+    ptr = apr_shm_baseaddr_get((apr_shm_t *)res->shm);
     memcpy(&desc, ptr, sizeof(desc));
     ptr = ptr + sizeof(desc);
 
     /* For the chained slotmem stuff */
-    res->name = apr_pstrdup(globalpool, fname);
+    res->name = apr_pstrdup(gpool, fname);
     res->base = ptr;
     res->size = desc.item_size;
     res->num = desc.item_num;
-    res->globalpool = globalpool;
-    res->sharedmem_mutex = sharedmem_mutex;
+    res->gpool = gpool;
+    res->smutex = smutex;
     res->next = NULL;
     if (globallistmem == NULL) {
 	globallistmem = res;
@@ -346,12 +335,12 @@
 
 static apr_status_t ap_slotmem_lock(ap_slotmem_t *slot)
 {
-    return (apr_global_mutex_lock(slot->sharedmem_mutex));    
+    return (apr_global_mutex_lock(slot->smutex));    
 }
 
 static apr_status_t ap_slotmem_unlock(ap_slotmem_t *slot)
 {
-    return (apr_global_mutex_unlock(slot->sharedmem_mutex));
+    return (apr_global_mutex_unlock(slot->smutex));
 }
 
 static const slotmem_storage_method storage = {
@@ -370,9 +359,9 @@
 }
 
 /* initialise the global pool */
-static void sharedmem_initglobalpool(apr_pool_t *p)
+static void sharedmem_initgpool(apr_pool_t *p)
 {
-    globalpool = p;
+    gpool = p;
 }
 
 /* Add the pool_clean routine */
@@ -424,7 +413,7 @@
         return rv;
     }
 
-    rv = apr_global_mutex_create(&sharedmem_mutex,
+    rv = apr_global_mutex_create(&smutex,
                                  mutex_fname, APR_LOCK_DEFAULT, p);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
@@ -433,7 +422,7 @@
     }
 
 #ifdef AP_NEED_SET_MUTEX_PERMS
-    rv = ap_unixd_set_global_mutex_perms(sharedmem_mutex);
+    rv = ap_unixd_set_global_mutex_perms(smutex);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
                      "sharedmem: failed to set mutex permissions");
@@ -457,7 +446,7 @@
 	    "Fatal error: unable to create global pool for shared slotmem");
 	return rv;
     }
-    sharedmem_initglobalpool(global_pool);
+    sharedmem_initgpool(global_pool);
     return OK;
 }
 
@@ -465,7 +454,7 @@
 {
     apr_status_t rv;
 
-    rv = apr_global_mutex_child_init(&sharedmem_mutex,
+    rv = apr_global_mutex_child_init(&smutex,
                                      mutex_fname, p);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,

Modified: httpd/httpd/trunk/modules/mem/slotmem.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/slotmem.h?rev=730133&r1=730132&r2=730133&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/slotmem.h (original)
+++ httpd/httpd/trunk/modules/mem/slotmem.h Tue Dec 30 05:59:17 2008
@@ -52,6 +52,19 @@
 
 typedef struct ap_slotmem ap_slotmem_t; 
 
+struct ap_slotmem {
+    char                 *name;       /* per segment name */
+    void                 *shm;        /* ptr to memory segment (apr_shm_t *) */
+    void                 *base;       /* data set start */
+    apr_size_t           size;        /* size of each memory slot */
+    int                  num;         /* number of mem slots */
+    apr_pool_t           *gpool;      /* per segment global pool */
+    apr_global_mutex_t   *smutex;     /* mutex */
+    void                 *context;    /* general purpose storage */
+    struct ap_slotmem    *next;       /* location of next allocated segment */
+};
+
+
 /**
  * callback function used for slotmem.
  * @param mem is the memory associated with a worker.



Mime
View raw message