From 3b3134610348a56bbf25cfd256b0f36908d0d752 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Sun, 16 Apr 2006 17:32:54 +0000 Subject: Commit tagcache in background when possible (at least dircache enabled). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9686 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/dircache.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'firmware/common') diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index 9a0bcb6..e5ee77c 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c @@ -567,6 +567,7 @@ static int dircache_do_rebuild(void) audiobuf += (long)((dircache_size & ~0x03) + 0x04); audiobuf += DIRCACHE_RESERVE; allocated_size = dircache_size + DIRCACHE_RESERVE; + reserve_used = 0; } return 1; @@ -612,27 +613,20 @@ static void dircache_thread(void) */ int dircache_build(int last_size) { - if (dircache_initialized) + if (dircache_initialized || thread_enabled) return -3; - while (thread_enabled) - sleep(1); - logf("Building directory cache"); if (dircache_size > 0) { - allocated_size = dircache_size + (DIRCACHE_RESERVE-reserve_used); thread_enabled = true; queue_post(&dircache_queue, DIRCACHE_BUILD, 0); return 2; } - else - { - dircache_root = (struct dircache_entry *)(((long)audiobuf & ~0x03) + 0x04); - dircache_size = 0; - } + + dircache_root = (struct dircache_entry *)(((long)audiobuf & ~0x03) + 0x04); - if (last_size > DIRCACHE_RESERVE && last_size < DIRCACHE_LIMIT) + if (last_size > DIRCACHE_RESERVE && last_size < DIRCACHE_LIMIT ) { allocated_size = last_size + DIRCACHE_RESERVE; @@ -650,6 +644,23 @@ int dircache_build(int last_size) } /** + * Steal the allocated dircache buffer and disable dircache. + */ +void* dircache_steal_buffer(long *size) +{ + dircache_disable(); + if (dircache_size == 0) + { + *size = 0; + return NULL; + } + + *size = dircache_size + (DIRCACHE_RESERVE-reserve_used); + + return dircache_root; +} + +/** * Main initialization function that must be called before any other * operations within the dircache. */ -- cgit v1.1