From: Cliff Woolley Date: Tue, 2 Dec 2003 19:07:41 +0000 (+0000) Subject: Fixed mod_mem_cache so that it doesn't misfile entries in the priority X-Git-Tag: pre_ajp_proxy~963 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c09066b0d09dd3fc33efebf794cd55ae4214c9a;p=apache Fixed mod_mem_cache so that it doesn't misfile entries in the priority queue. Previously, since the ->priority value was positive, certain parts of mod_mem_cache would cause the priority queue to do the wrong thing when changing the priority of an object in the cache. The end result would be that the objects would not be dequeued in the right order. Submitted by: Jean-Jacques Clar, Cliff Woolley Reviewed by: Paul J. Reder git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101958 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/experimental/mod_mem_cache.c b/modules/experimental/mod_mem_cache.c index 29be329033..f8fb0b3d28 100644 --- a/modules/experimental/mod_mem_cache.c +++ b/modules/experimental/mod_mem_cache.c @@ -232,20 +232,21 @@ static void memcache_cache_free(void*a) #endif } /* - * functions return a 'negative' score as lower is better in a priority Q + * functions return a 'negative' score since priority queues + * dequeue the object with the highest value first */ static long memcache_lru_algorithm(long queue_clock, void *a) { cache_object_t *obj = (cache_object_t *)a; mem_cache_object_t *mobj = obj->vobj; if (mobj->priority == 0) - mobj->priority = ((long)(queue_clock + mobj->total_refs)); + mobj->priority = -((long)(queue_clock + mobj->total_refs)); /* * a 'proper' LRU function would just be * mobj->priority = mobj->total_refs; */ - return -1*mobj->priority; + return mobj->priority; } static long memcache_gdsf_algorithm(long queue_clock, void *a) @@ -254,9 +255,10 @@ static long memcache_gdsf_algorithm(long queue_clock, void *a) mem_cache_object_t *mobj = obj->vobj; if (mobj->priority == 0) - mobj->priority = queue_clock + (long)(mobj->total_refs*1000 / mobj->m_len); + mobj->priority = -(queue_clock + + (long)(mobj->total_refs*1000 / mobj->m_len)); - return -1*mobj->priority; + return mobj->priority; } static void cleanup_cache_object(cache_object_t *obj)