From f5069d88dff7a7ed2f4665904b03e906cca75a7c Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 11 Dec 2006 09:57:58 +0100 Subject: Fix cache algorithm loophole This closes the door for unneccessary calls to cgit_fill_cache(). Noticed by Linus. Signed-off-by: Lars Hjemli --- cgit.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 110face..7f14016 100644 --- a/cgit.c +++ b/cgit.c @@ -465,20 +465,20 @@ static void cgit_fill_cache(struct cacheitem *item) static void cgit_refresh_cache(struct cacheitem *item) { + cache_prepare(item); top: - if (!cache_lookup(item)) { - if (cache_lock(item)) { - cgit_fill_cache(item); - cache_unlock(item); - } else { + if (!cache_exist(item)) { + if (!cache_lock(item)) { sched_yield(); goto top; } - } else if (cache_expired(item)) { - if (cache_lock(item)) { + if (!cache_exist(item)) cgit_fill_cache(item); - cache_unlock(item); - } + cache_unlock(item); + } else if (cache_expired(item) && cache_lock(item)) { + if (cache_expired(item)) + cgit_fill_cache(item); + cache_unlock(item); } } -- cgit 1.4.1