httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@apache.org
Subject cvs commit: httpd-2.0/modules/experimental mod_mem_cache.c
Date Sat, 15 Jun 2002 16:49:20 GMT
stoddard    2002/06/15 09:49:19

  Modified:    modules/experimental mod_mem_cache.c
  Log:
  Close race condition cleaning up cache entry.
  
  Revision  Changes    Path
  1.72      +27 -2     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.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- mod_mem_cache.c	15 Jun 2002 01:04:40 -0000	1.71
  +++ mod_mem_cache.c	15 Jun 2002 16:49:19 -0000	1.72
  @@ -192,12 +192,37 @@
   }
   /** 
    * callback to free an entry 
  - * XXX: just call cleanup_cache_object ?
  + * There is way too much magic in this code. Right now, this callback
  + * is only called out of cache_insert() which is called under protection
  + * of the sconf->lock, which means that we do not (and should not)
  + * attempt to obtain the lock recursively. 
    */
   static void memcache_cache_free(void*a)
   {
       cache_object_t *obj = (cache_object_t *)a;
  -    cleanup_cache_object(obj);
  +
  +    /* Cleanup the cache object. Object should be removed from the cache
  +     * now. Increment the refcount before setting cleanup to avoid a race 
  +     * condition. A similar pattern is used in remove_url()
  +     */
  +#ifdef USE_ATOMICS
  +    apr_atomic_inc(&obj->refcount);
  +#else
  +    obj->refcount++;
  +#endif
  +
  +    obj->cleanup = 1;
  +
  +#ifdef USE_ATOMICS
  +    if (!apr_atomic_dec(&obj->refcount)) {
  +        cleanup_cache_object(obj);
  +    }
  +#else
  +    obj->refcount--;
  +    if (!obj->refcount) {
  +        cleanup_cache_object(obj);
  +    }
  +#endif
   }
   /*
    * functions return a 'negative' score as lower is better in a priority Q
  
  
  

Mime
View raw message