]> granicus.if.org Git - apache/commitdiff
Fixed mod_mem_cache so that it doesn't misfile entries in the priority
authorCliff Woolley <jwoolley@apache.org>
Tue, 2 Dec 2003 19:07:41 +0000 (19:07 +0000)
committerCliff Woolley <jwoolley@apache.org>
Tue, 2 Dec 2003 19:07:41 +0000 (19:07 +0000)
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

modules/experimental/mod_mem_cache.c

index 29be32903363e201cf5ee7e933204835721d0c7b..f8fb0b3d281f1a68c29df2aed4ec631320b83553 100644 (file)
@@ -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)