aboutsummaryrefslogtreecommitdiffstats
path: root/cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'cache.c')
-rw-r--r--cache.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/cache.c b/cache.c
index 6fdbd25..3f7d3f8 100644
--- a/cache.c
+++ b/cache.c
@@ -64,20 +64,25 @@ struct cache_struct * get_cache_block(__u32 block)
for ( i = 0; i < CACHE_ENTRIES; i ++ ) {
if ( cs->block == block )
- goto hit;
+ break;
else
cs = &cache[i + 1];
}
- /* we missed it here, so we need to load it */
- miss:
- /* store it at head of real cache */
- cs = cache[0].next;
-
- cs->block = block;
- cs->data = (void*)getoneblk(block);
+ if ( i == CACHE_ENTRIES ) {
+ /* missed, so we need to load it */
- hit:
+ /* first free it if nessary */
+ if ( cache[0].next->data )
+ free(cache[0].next->data);
+
+ /* store it at the head of real cache */
+ cs = cache[0].next;
+
+ cs->block = block;
+ cs->data = (void*)getoneblk(block);
+ }
+
/* remove cs from current position in list */
cs->prev->next = cs->next;
cs->next->prev = cs->prev;