From mboxrd@z Thu Jan 1 00:00:00 1970 From: cgit at cryptocrack.de (Lukas Fleischer) Date: Wed, 15 Jan 2014 22:37:07 +0100 Subject: [PATCH 4/4] Remove callback data parameter for cache slots In-Reply-To: <1389821827-3483-1-git-send-email-cgit@cryptocrack.de> References: <1389821827-3483-1-git-send-email-cgit@cryptocrack.de> Message-ID: <1389821827-3483-5-git-send-email-cgit@cryptocrack.de> This is no longer needed since the context is always read from the global context variable. Signed-off-by: Lukas Fleischer --- cache.c | 14 ++++++-------- cache.h | 5 ++--- cgit.c | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cache.c b/cache.c index fa83ddc..fcd461f 100644 --- a/cache.c +++ b/cache.c @@ -24,7 +24,6 @@ struct cache_slot { int keylen; int ttl; cache_fill_fn fn; - void *cbdata; int cache_fd; int lock_fd; const char *cache_name; @@ -187,7 +186,7 @@ static int fill_slot(struct cache_slot *slot) return errno; /* Generate cache content */ - slot->fn(slot->cbdata); + slot->fn(); /* Restore stdout */ if (dup2(tmp, STDOUT_FILENO) == -1) @@ -277,7 +276,7 @@ static int process_slot(struct cache_slot *slot) if ((err = lock_slot(slot)) != 0) { cache_log("[cgit] Unable to lock slot %s: %s (%d)\n", slot->lock_name, strerror(err), err); - slot->fn(slot->cbdata); + slot->fn(); return 0; } @@ -286,7 +285,7 @@ static int process_slot(struct cache_slot *slot) slot->lock_name, strerror(err), err); unlock_slot(slot, 0); close_lock(slot); - slot->fn(slot->cbdata); + slot->fn(); return 0; } // We've got a valid cache slot in the lock file, which @@ -310,7 +309,7 @@ static int process_slot(struct cache_slot *slot) /* Print cached content to stdout, generate the content if necessary. */ int cache_process(int size, const char *path, const char *key, int ttl, - cache_fill_fn fn, void *cbdata) + cache_fill_fn fn) { unsigned long hash; int i; @@ -321,14 +320,14 @@ int cache_process(int size, const char *path, const char *key, int ttl, /* If the cache is disabled, just generate the content */ if (size <= 0) { - fn(cbdata); + fn(); return 0; } /* Verify input, calculate filenames */ if (!path) { cache_log("[cgit] Cache path not specified, caching is disabled\n"); - fn(cbdata); + fn(); return 0; } if (!key) @@ -343,7 +342,6 @@ int cache_process(int size, const char *path, const char *key, int ttl, strbuf_addbuf(&lockname, &filename); strbuf_addstr(&lockname, ".lock"); slot.fn = fn; - slot.cbdata = cbdata; slot.ttl = ttl; slot.cache_name = filename.buf; slot.lock_name = lockname.buf; diff --git a/cache.h b/cache.h index 5cfdb4f..9392836 100644 --- a/cache.h +++ b/cache.h @@ -6,7 +6,7 @@ #ifndef CGIT_CACHE_H #define CGIT_CACHE_H -typedef void (*cache_fill_fn)(void *cbdata); +typedef void (*cache_fill_fn)(void); /* Print cached content to stdout, generate the content if necessary. @@ -17,13 +17,12 @@ typedef void (*cache_fill_fn)(void *cbdata); * key the key used to lookup cache files * ttl max cache time in seconds for this key * fn content generator function for this key - * cbdata user-supplied data to the content generator function * * Return value * 0 indicates success, everyting else is an error */ extern int cache_process(int size, const char *path, const char *key, int ttl, - cache_fill_fn fn, void *cbdata); + cache_fill_fn fn); /* List info about all cache entries on stdout */ diff --git a/cgit.c b/cgit.c index 19bcd0d..9ea4099 100644 --- a/cgit.c +++ b/cgit.c @@ -593,7 +593,7 @@ static int prepare_repo_cmd(void) return 0; } -static void process_request(void *cbdata) +static void process_request(void) { struct cgit_cmd *cmd; @@ -957,7 +957,7 @@ int main(int argc, const char **argv) if (ctx.cfg.nocache) ctx.cfg.cache_size = 0; err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, - ctx.qry.raw, ttl, process_request, NULL); + ctx.qry.raw, ttl, process_request); cgit_cleanup_filters(); if (err) cgit_print_error("Error processing page: %s (%d)", -- 1.8.5.2