aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-05-12 12:32:39 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-05-12 12:32:39 +0800
commit52ab97cab14939b665d6c66b00564004c3911e65 (patch)
tree176584ebb4c0c0dae91b89f462f8ba7f3aad8763
parent516183b9ea5424090ea285a3d667d45553d1860e (diff)
downloaddevel-52ab97cab14939b665d6c66b00564004c3911e65.tar.gz
devel-52ab97cab14939b665d6c66b00564004c3911e65.tar.xz
devel-52ab97cab14939b665d6c66b00564004c3911e65.zip
Changing on cache.c to make it more like C
-rwxr-xr-xa.outbin26980 -> 27056 bytes
-rw-r--r--cache.c23
2 files changed, 14 insertions, 9 deletions
diff --git a/a.out b/a.out
index d1b97e9..6df4cc2 100755
--- a/a.out
+++ b/a.out
Binary files differ
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;