You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@apache.org on 2001/08/24 18:46:43 UTC

cvs commit: httpd-2.0/modules/experimental config.m4 mod_mem_cache.c

trawick     01/08/24 09:46:43

  Modified:    modules/experimental config.m4 mod_mem_cache.c
  Log:
  mod_mem_cache
  
  allow it to be enabled
  
  don't segfault if we don't have/need a lock
  
  clear up several compile warnings
  
  Revision  Changes    Path
  1.13      +1 -0      httpd-2.0/modules/experimental/config.m4
  
  Index: config.m4
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/config.m4,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- config.m4	2001/08/23 19:37:23	1.12
  +++ config.m4	2001/08/24 16:46:43	1.13
  @@ -10,6 +10,7 @@
   " 
   APACHE_MODULE(cache, dynamic file caching, $cache_objs, , no)
   APACHE_MODULE(disk_cache, disk caching module, , , no)
  +APACHE_MODULE(mem_cache, memory caching module, , , no)
   APACHE_MODULE(example, example and demo module, , , no)
   APACHE_MODULE(ext_filter, external filter module, , , no)
   APACHE_MODULE(case_filter, example uppercase conversion filter, , , no)
  
  
  
  1.3       +40 -14    httpd-2.0/modules/experimental/mod_mem_cache.c
  
  Index: mod_mem_cache.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/experimental/mod_mem_cache.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mod_mem_cache.c	2001/08/24 15:15:57	1.2
  +++ mod_mem_cache.c	2001/08/24 16:46:43	1.3
  @@ -59,6 +59,7 @@
   #define CORE_PRIVATE
   
   #include "mod_cache.h"
  +#include "ap_mpm.h"
   #define MAX_CACHE 5000
   module AP_MODULE_DECLARE_DATA mem_cache_module;
   
  @@ -170,6 +171,8 @@
   }
   static void *create_cache_config(apr_pool_t *p, server_rec *s)
   {
  +    int threaded_mpm;
  +
       sconf = apr_pcalloc(p, sizeof(mem_cache_conf));
       sconf->space = DEFAULT_CACHE_SPACE;
   #if 0
  @@ -177,7 +180,10 @@
       sconf->defaultexpire = DEFAULT_CACHE_EXPIRE;
   #endif
   
  -    apr_lock_create(&sconf->lock, APR_MUTEX, APR_INTRAPROCESS, "foo", p);
  +    ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm);
  +    if (threaded_mpm) {
  +        apr_lock_create(&sconf->lock, APR_MUTEX, APR_INTRAPROCESS, "foo", p);
  +    }
       sconf->cacheht = apr_hash_make(p);
       apr_pool_cleanup_register(p, NULL, cleanup_cache_mem, apr_pool_cleanup_null);
   
  @@ -245,10 +251,14 @@
       /* Mark the cache object as incomplete and put it into the cache */
       obj->complete = 0;
   
  -    /* XXX Need a way to insert into the cache w/o sch coarse grained locking */
  -    apr_lock_acquire(sconf->lock);
  +    /* XXX Need a way to insert into the cache w/o such coarse grained locking */
  +    if (sconf->lock) {
  +        apr_lock_acquire(sconf->lock);
  +    }
       apr_hash_set(sconf->cacheht, obj->key, strlen(obj->key), obj);
  -    apr_lock_release(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_release(sconf->lock);
  +    }
   
       return OK;
   }
  @@ -262,9 +272,13 @@
       if (strcasecmp(type, "mem")) {
           return DECLINED;
       }
  -    apr_lock_acquire(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_acquire(sconf->lock);
  +    }
       obj = (cache_object_t *) apr_hash_get(sconf->cacheht, key, APR_HASH_KEY_STRING);
  -    apr_lock_release(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_release(sconf->lock);
  +    }
   
       if (!obj || !(obj->complete)) {
           return DECLINED;
  @@ -292,9 +306,13 @@
   {
       cache_object_t *obj = (cache_object_t *) h->cache_obj;
   
  -    apr_lock_acquire(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_acquire(sconf->lock);
  +    }
       apr_hash_set(sconf->cacheht, obj->key, strlen(obj->key), NULL);
  -    apr_lock_release(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_release(sconf->lock);
  +    }
   
       cleanup_cache_object(obj);
       
  @@ -303,6 +321,7 @@
   
       /* The caller should free the cache_handle ? */
       free(h);
  +    return OK;
   }
   
   /* Define request processing hook handlers */
  @@ -321,18 +340,26 @@
        */
   
       /* First, find the object in the cache */
  -    apr_lock_acquire(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_acquire(sconf->lock);
  +    }
       obj = (cache_object_t *) apr_hash_get(sconf->cacheht, key, APR_HASH_KEY_STRING);
  -    apr_lock_release(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_release(sconf->lock);
  +    }
   
       if (!obj) {
           return DECLINED;
       }
   
       /* Found it. Now take it out of the cache and free it. */
  -    apr_lock_acquire(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_acquire(sconf->lock);
  +    }
       apr_hash_set(sconf->cacheht, obj->key, strlen(obj->key), NULL);
  -    apr_lock_release(sconf->lock);
  +    if (sconf->lock) {
  +        apr_lock_release(sconf->lock);
  +    }
   
       cleanup_cache_object(obj);
   
  @@ -385,7 +412,6 @@
   static int write_body(cache_handle *h, apr_bucket_brigade *b) 
   {
       apr_status_t rv;
  -    apr_size_t idx = 0;
       cache_object_t *obj = (cache_object_t *) h->cache_obj;
       apr_read_type_e eblock = APR_BLOCK_READ;
       apr_bucket *e;
  @@ -425,7 +451,7 @@
   }
   
   static const char 
  -*set_cache_size(cmd_parms *parms, char *struct_ptr, char *arg)
  +*set_cache_size(cmd_parms *parms, void *in_struct_ptr, const char *arg)
   {
       int val;
   
  
  
  

Re: cvs commit: httpd-2.0/modules/experimental config.m4 mod_mem_cache.c

Posted by Jeff Trawick <tr...@attglobal.net>.
trawick@apache.org writes:

>   don't segfault if we don't have/need a lock
>   Index: mod_mem_cache.c

>   -    apr_lock_acquire(sconf->lock);
>   +    /* XXX Need a way to insert into the cache w/o such coarse grained locking */
>   +    if (sconf->lock) {
>   +        apr_lock_acquire(sconf->lock);
>   +    }

it would be kind of cool to have an APR noop lock to avoid this kind
of ugliness; wasted pathlength but prettier :)

-- 
Jeff Trawick | trawick@attglobal.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: cvs commit: httpd-2.0/modules/experimental config.m4 mod_mem_cache.c

Posted by Jeff Trawick <tr...@attglobal.net>.
trawick@apache.org writes:

>   don't segfault if we don't have/need a lock
>   Index: mod_mem_cache.c

>   -    apr_lock_acquire(sconf->lock);
>   +    /* XXX Need a way to insert into the cache w/o such coarse grained locking */
>   +    if (sconf->lock) {
>   +        apr_lock_acquire(sconf->lock);
>   +    }

it would be kind of cool to have an APR noop lock to avoid this kind
of ugliness; wasted pathlength but prettier :)

-- 
Jeff Trawick | trawick@attglobal.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...