httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r742992 - in /httpd/httpd/trunk: include/ap_slotmem.h modules/mem/mod_plainmem.c modules/mem/mod_sharedmem.c server/slotmem.c
Date Tue, 10 Feb 2009 15:16:54 GMT
Author: jim
Date: Tue Feb 10 15:16:24 2009
New Revision: 742992

URL: http://svn.apache.org/viewvc?rev=742992&view=rev
Log:
Add getter/setter functions to the slotmem API. Also,
reset the id vars to unsigned ints universally.

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

Modified: httpd/httpd/trunk/include/ap_slotmem.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_slotmem.h?rev=742992&r1=742991&r2=742992&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_slotmem.h (original)
+++ httpd/httpd/trunk/include/ap_slotmem.h Tue Feb 10 15:16:24 2009
@@ -56,7 +56,7 @@
  * callback function used for slotmem.
  * @param mem is the memory associated with a worker.
  * @param data is what is passed to slotmem.
- * @param pool is pool used to create scoreboard
+ * @param pool is pool used
  * @return APR_SUCCESS if all went well
  */
 typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool);
@@ -71,40 +71,38 @@
      * @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
+     * @param pool is pool used
      * @return APR_SUCCESS if all went well
      */
     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.
      * 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
+     * @param pool is pool used
      * @return APR_SUCCESS if all went well
      */
-    apr_status_t (* 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,
unsigned 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
      */
-    apr_status_t (* 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,
unsigned int *item_num, apr_pool_t *pool);
     /**
-     * get the memory associated with this worker slot.
+     * get the memory ptr 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
      */
-    apr_status_t (* slotmem_mem)(ap_slotmem_t *s, int item_id, void**mem);
+    apr_status_t (* slotmem_mem)(ap_slotmem_t *s, unsigned int item_id, void**mem);
     /**
      * lock the memory segment
      * NOTE: All slots share the same mutex
@@ -119,6 +117,24 @@
      * @return APR_SUCCESS if all went well
      */
     apr_status_t (* slotmem_unlock)(ap_slotmem_t *s);
+    /**
+     * retrieve 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 dest address to store the data
+     * @param dest_len length of dataset to retrieve
+     * @return APR_SUCCESS if all went well
+     */
+    apr_status_t (* slotmem_get)(ap_slotmem_t *s, unsigned int item_id, unsigned char *dest,
apr_size_t dest_len);
+    /**
+     * store 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 src address of the data to store in the slot
+     * @param src_len length of dataset to store in the slot
+     * @return APR_SUCCESS if all went well
+     */
+    apr_status_t (* slotmem_put)(ap_slotmem_t *slot, unsigned int item_id, unsigned char
*src, apr_size_t src_len);
 };
 
 typedef struct ap_slotmem_storage_method ap_slotmem_storage_method;
@@ -149,7 +165,7 @@
  * @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
+ * @param pool is pool used
  * @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);
@@ -157,37 +173,39 @@
 /**
  * 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 sm ap_slotmem_storage_method provider obtained
  * @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
+ * @param pool is pool used
  * @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);
+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, unsigned 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 sm ap_slotmem_storage_method provider obtained
  * @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);
+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, unsigned int *item_num, apr_pool_t *pool);
 /**
  * get the memory associated with this worker slot.
+ * @param sm ap_slotmem_storage_method provider obtained
  * @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);
+AP_DECLARE(apr_status_t) ap_slotmem_mem(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned
int item_id, void**mem);
 /**
  * lock the memory segment
  * NOTE: All slots share the same mutex
+ * @param sm ap_slotmem_storage_method provider obtained
  * @param s ap_slotmem_t to use
  * @return APR_SUCCESS if all went well
  */
@@ -195,9 +213,30 @@
 /**
  * unlock the memory segment
  * NOTE: All slots share the same mutex
+ * @param sm ap_slotmem_storage_method provider obtained
  * @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);
+/**
+ * retrieve the memory associated with this worker slot.
+ * @param sm ap_slotmem_storage_method provider obtained
+ * @param s ap_slotmem_t to use.
+ * @param item_id item to return for 0 to item_num
+ * @param dest address to store the data
+ * @param dest_len length of dataset to retrieve
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_get(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned
int item_id, unsigned char *dest, apr_size_t dest_len);
+/**
+ * store the memory associated with this worker slot.
+ * @param sm ap_slotmem_storage_method provider obtained
+ * @param s ap_slotmem_t to use.
+ * @param item_id item to return for 0 to item_num
+ * @param src address of the data to store in the slot
+ * @param src_len length of dataset to store in the slot
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_slotmem_put(ap_slotmem_storage_method *sm, ap_slotmem_t *s, unsigned
int item_id, unsigned char *src, apr_size_t src_len);
 
 #endif /*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=742992&r1=742991&r2=742992&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_plainmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_plainmem.c Tue Feb 10 15:16:24 2009
@@ -24,7 +24,7 @@
     char                 *name;       /* per segment name */
     void                 *base;       /* data set start */
     apr_size_t           size;        /* size of each memory slot */
-    int                  num;         /* number of mem slots */
+    unsigned int         num;         /* number of mem slots */
     apr_pool_t           *gpool;      /* per segment global pool */
     apr_global_mutex_t   *smutex;     /* mutex */
     struct ap_slotmem_t  *next;       /* location of next allocated segment */
@@ -37,7 +37,7 @@
 
 static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data,
apr_pool_t *pool)
 {
-    int i;
+    unsigned int i;
     void *ptr;
 
     if (!mem)
@@ -51,7 +51,7 @@
     return APR_SUCCESS;
 }
 
-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)
+static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size,
unsigned int item_num, apr_pool_t *pool)
 {
     ap_slotmem_t *res;
     ap_slotmem_t *next = globallistmem;
@@ -100,7 +100,7 @@
     return APR_SUCCESS;
 }
 
-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)
+static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size,
unsigned int *item_num, apr_pool_t *pool)
 {
     ap_slotmem_t *next = globallistmem;
     const char *fname;
@@ -133,7 +133,7 @@
     return APR_ENOSHMAVAIL;
 }
 
-static apr_status_t slotmem_mem(ap_slotmem_t *score, int id, void **mem)
+static apr_status_t slotmem_mem(ap_slotmem_t *score, unsigned int id, void **mem)
 {
 
     void *ptr;
@@ -150,6 +150,34 @@
     return APR_SUCCESS;
 }
 
+static apr_status_t slotmem_get(ap_slotmem_t *slot, unsigned int id, unsigned char *dest,
apr_size_t dest_len)
+{
+
+    void *ptr;
+    apr_status_t ret;
+
+    ret = slotmem_mem(slot, id, &ptr);
+    if (ret != APR_SUCCESS) {
+        return ret;
+    }
+    memcpy(dest, ptr, dest_len); /* bounds check? */
+    return APR_SUCCESS;
+}
+
+static apr_status_t slotmem_put(ap_slotmem_t *slot, unsigned int id, unsigned char *src,
apr_size_t src_len)
+{
+
+    void *ptr;
+    apr_status_t ret;
+
+    ret = slotmem_mem(slot, id, &ptr);
+    if (ret != APR_SUCCESS) {
+        return ret;
+    }
+    memcpy(ptr, src, src_len); /* bounds check? */
+    return APR_SUCCESS;
+}
+
 static const ap_slotmem_storage_method storage = {
     "plainmem",
     &slotmem_do,

Modified: httpd/httpd/trunk/modules/mem/mod_sharedmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_sharedmem.c?rev=742992&r1=742991&r2=742992&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_sharedmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_sharedmem.c Tue Feb 10 15:16:24 2009
@@ -25,7 +25,7 @@
     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 */
+    unsigned int         num;         /* number of mem slots */
     apr_pool_t           *gpool;      /* per segment global pool */
     apr_global_mutex_t   *smutex;     /* mutex */
     struct ap_slotmem_t  *next;       /* location of next allocated segment */
@@ -35,7 +35,7 @@
 /* The description of the slots to reuse the slotmem */
 struct sharedslotdesc {
     apr_size_t item_size;
-    int item_num;
+    unsigned int item_num;
 };
 
 /* global pool and list of slotmem we are handling */
@@ -92,7 +92,7 @@
     apr_file_close(fp);
 }
 
-static void restore_slotmem(void *ptr, const char *name, apr_size_t item_size, int item_num,
apr_pool_t *pool)
+static void restore_slotmem(void *ptr, const char *name, apr_size_t item_size, unsigned int
item_num, apr_pool_t *pool)
 {
     const char *storename;
     apr_file_t *fp;
@@ -138,7 +138,7 @@
 
 static apr_status_t slotmem_do(ap_slotmem_t *mem, ap_slotmem_callback_fn_t *func, void *data,
apr_pool_t *pool)
 {
-    int i;
+    unsigned int i;
     void *ptr;
 
     if (!mem) {
@@ -153,7 +153,7 @@
     return APR_SUCCESS;
 }
 
-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)
+static apr_status_t slotmem_create(ap_slotmem_t **new, const char *name, apr_size_t item_size,
unsigned int item_num, apr_pool_t *pool)
 {
 /*    void *slotmem = NULL; */
     void *ptr;
@@ -255,7 +255,7 @@
     return APR_SUCCESS;
 }
 
-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)
+static apr_status_t slotmem_attach(ap_slotmem_t **new, const char *name, apr_size_t *item_size,
unsigned int *item_num, apr_pool_t *pool)
 {
 /*    void *slotmem = NULL; */
     void *ptr;
@@ -331,7 +331,7 @@
     return APR_SUCCESS;
 }
 
-static apr_status_t slotmem_mem(ap_slotmem_t *slot, int id, void **mem)
+static apr_status_t slotmem_mem(ap_slotmem_t *slot, unsigned int id, void **mem)
 {
 
     void *ptr;
@@ -361,6 +361,34 @@
     return (apr_global_mutex_unlock(slot->smutex));
 }
 
+static apr_status_t slotmem_get(ap_slotmem_t *slot, unsigned int id, unsigned char *dest,
apr_size_t dest_len)
+{
+
+    void *ptr;
+    apr_status_t ret;
+
+    ret = slotmem_mem(slot, id, &ptr);
+    if (ret != APR_SUCCESS) {
+        return ret;
+    }
+    memcpy(dest, ptr, dest_len); /* bounds check? */
+    return APR_SUCCESS;
+}
+
+static apr_status_t slotmem_put(ap_slotmem_t *slot, unsigned int id, unsigned char *src,
apr_size_t src_len)
+{
+
+    void *ptr;
+    apr_status_t ret;
+
+    ret = slotmem_mem(slot, id, &ptr);
+    if (ret != APR_SUCCESS) {
+        return ret;
+    }
+    memcpy(ptr, src, src_len); /* bounds check? */
+    return APR_SUCCESS;
+}
+
 static const ap_slotmem_storage_method storage = {
     "sharedmem",
     &slotmem_do,
@@ -368,7 +396,9 @@
     &slotmem_attach,
     &slotmem_mem,
     &slotmem_lock,
-    &slotmem_unlock
+    &slotmem_unlock,
+    &slotmem_get,
+    &slotmem_put
 };
 
 /* make the storage usuable from outside */

Modified: httpd/httpd/trunk/server/slotmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/slotmem.c?rev=742992&r1=742991&r2=742992&view=diff
==============================================================================
--- httpd/httpd/trunk/server/slotmem.c (original)
+++ httpd/httpd/trunk/server/slotmem.c Tue Feb 10 15:16:24 2009
@@ -41,7 +41,7 @@
 
 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_size_t item_size, unsigned int item_num,
                                            apr_pool_t *pool)
 {
     return (sm->slotmem_create(new, name, item_size, item_num, pool));
@@ -49,14 +49,14 @@
 
 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_size_t *item_size, unsigned int *item_num,
                                            apr_pool_t *pool)
 {
     return (sm->slotmem_attach(new, name, item_size, item_num, pool));
 }
 
 AP_DECLARE(apr_status_t) ap_slotmem_mem(ap_slotmem_storage_method *sm,
-                                        ap_slotmem_t *s, int item_id, void**mem)
+                                        ap_slotmem_t *s, unsigned int item_id, void**mem)
 {
     return (sm->slotmem_mem(s, item_id, mem));
 }
@@ -73,6 +73,18 @@
     return (sm->slotmem_unlock(s));
 }
 
+AP_DECLARE(apr_status_t) ap_slotmem_get(ap_slotmem_storage_method *sm,
+                                        ap_slotmem_t *s, unsigned int item_id,
+                                        unsigned char *dest, apr_size_t dest_len)
+{
+    return (sm->slotmem_get(s, item_id, dest, dest_len));
+}
+AP_DECLARE(apr_status_t) ap_slotmem_put(ap_slotmem_storage_method *sm, ap_slotmem_t *s,
+                                        unsigned int item_id, unsigned char *src,
+                                        apr_size_t src_len)
+{
+    return (sm->slotmem_put(s, item_id, src, src_len));
+}
 
 module AP_MODULE_DECLARE_DATA slotmem_module = {
     STANDARD20_MODULE_STUFF,



Mime
View raw message