You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2009/05/13 20:27:06 UTC
svn commit: r774473 - /httpd/httpd/trunk/modules/mem/mod_sharedmem.c
Author: jim
Date: Wed May 13 18:27:04 2009
New Revision: 774473
URL: http://svn.apache.org/viewvc?rev=774473&view=rev
Log:
Add in draft grab/return (alloc/free)... not in API yet.
Modified:
httpd/httpd/trunk/modules/mem/mod_sharedmem.c
Modified: httpd/httpd/trunk/modules/mem/mod_sharedmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_sharedmem.c?rev=774473&r1=774472&r2=774473&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_sharedmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_sharedmem.c Wed May 13 18:27:04 2009
@@ -48,7 +48,7 @@
apr_pool_t *gpool; /* per segment global pool */
apr_global_mutex_t *smutex; /* mutex */
struct ap_slotmem_t *next; /* location of next allocated segment */
- char *inuse; /* is-use flag table*/
+ unsigned int *inuse; /* is-use flag table*/
};
@@ -449,8 +449,12 @@
{
void *ptr;
+ char *inuse = (slot->base + (slot->size * slot->num));
apr_status_t ret;
+ if (!inuse[id]) {
+ return APR_ENOSHMAVAIL;
+ }
ret = slotmem_mem(slot, id, &ptr);
if (ret != APR_SUCCESS) {
return ret;
@@ -463,17 +467,17 @@
{
void *ptr;
- char *inuse;
+ char *inuse = (slot->base + (slot->size * slot->num));
apr_status_t ret;
+ if (!inuse[id]) {
+ return APR_ENOSHMAVAIL;
+ }
ret = slotmem_mem(slot, id, &ptr);
if (ret != APR_SUCCESS) {
return ret;
}
memcpy(ptr, src, src_len); /* bounds check? */
- /* We know the id fit it */
- inuse = (slot->base + (slot->size * slot->num));
- inuse[id] = 1;
return APR_SUCCESS;
}
@@ -487,6 +491,53 @@
return slot->size;
}
+static apr_status_t slotmem_grab(ap_slotmem_t *slot, unsigned int *id)
+{
+
+ unsigned int i;
+ char *inuse;
+
+ if (!slot) {
+ return APR_ENOSHMAVAIL;
+ }
+ inuse = (slot->base + (slot->size * slot->num));
+
+ SLOTMEM_LOCK(slot->smutex);
+ for (i = 0; i < slot->num; i++, inuse++) {
+ if (!*inuse) {
+ break;
+ }
+ }
+ if (i >= slot->num) {
+ SLOTMEM_UNLOCK(slot->smutex);
+ return APR_ENOSHMAVAIL;
+ }
+ *inuse = 1;
+ *id = i;
+ SLOTMEM_UNLOCK(slot->smutex);
+ return APR_SUCCESS;
+}
+
+static apr_status_t slotmem_return(ap_slotmem_t *slot, unsigned int id)
+{
+
+ char *inuse;
+
+ if (!slot) {
+ return APR_ENOSHMAVAIL;
+ }
+ inuse = (slot->base + (slot->size * slot->num));
+
+ SLOTMEM_LOCK(slot->smutex);
+ if (!inuse[id]) {
+ SLOTMEM_UNLOCK(slot->smutex);
+ return APR_ENOSHMAVAIL;
+ }
+ inuse[id] = 0;
+ SLOTMEM_UNLOCK(slot->smutex);
+ return APR_SUCCESS;
+}
+
static const ap_slotmem_storage_method storage = {
"sharedmem",
&slotmem_do,