From 149bc03d86e1ae8c2d05fb9d657500252a8ba20a Mon Sep 17 00:00:00 2001 From: Steve Bavin Date: Thu, 8 Mar 2007 08:20:30 +0000 Subject: [PATCH] Really don't try to initialise while the database status is unknown git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12684 a1c6a512-1295-4272-9138-f99709370657 --- apps/root_menu.c | 59 +++++++++++++++++++++++++----------------------- apps/tagcache.c | 4 +++- apps/tagcache.h | 1 + 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/apps/root_menu.c b/apps/root_menu.c index fa00a06ed5..b9847dfd54 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c @@ -104,35 +104,17 @@ static int browser(void* param) case GO_TO_DBBROWSER: if (!tagcache_is_usable()) { - /* Check if we're still initialising, so status is unknown */ - struct tagcache_stat *stat = tagcache_get_stat(); - if (!stat->initialized) - { - gui_syncsplash(HZ*2, true, str(LANG_TAGCACHE_BUSY)); - return GO_TO_PREVIOUS; - } - - /* Re-init if required */ - if (!stat->ready && !stat->commit_delayed && stat->processed_entries == 0) - { - /* Prompt the user */ - char *lines[]={str(LANG_TAGCACHE_BUSY), str(LANG_TAGCACHE_FORCE_UPDATE)}; - struct text_message message={lines, 2}; - if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO) - return GO_TO_PREVIOUS; - int i; - FOR_NB_SCREENS(i) - screens[i].clear_display(); - - /* Start initialisation */ - tagcache_rebuild(); - } + bool reinit_attempted = false; /* Now display progress until it's ready or the user exits */ while(!tagcache_is_usable()) { gui_syncstatusbar_draw(&statusbars, false); - stat = tagcache_get_stat(); + struct tagcache_stat *stat = tagcache_get_stat(); + + /* Allow user to exit */ + if (action_userabort(HZ/2)) + break; /* Maybe just needs to reboot due to delayed commit */ if (stat->commit_delayed) @@ -141,6 +123,31 @@ static int browser(void* param) break; } + /* Check if ready status is known */ + if (!stat->readyvalid) + { + gui_syncsplash(0, true, str(LANG_TAGCACHE_BUSY)); + continue; + } + + /* Re-init if required */ + if (!reinit_attempted && !stat->ready && + stat->processed_entries == 0 && stat->commit_step == 0) + { + /* Prompt the user */ + reinit_attempted = true; + char *lines[]={str(LANG_TAGCACHE_BUSY), str(LANG_TAGCACHE_FORCE_UPDATE)}; + struct text_message message={lines, 2}; + if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_NO) + break; + int i; + FOR_NB_SCREENS(i) + screens[i].clear_display(); + + /* Start initialisation */ + tagcache_rebuild(); + } + /* Display building progress */ if (stat->commit_step > 0) { @@ -153,10 +160,6 @@ static int browser(void* param) gui_syncsplash(0, true, str(LANG_BUILDING_DATABASE), stat->processed_entries); } - - /* Allow user to exit */ - if (action_userabort(HZ/2)) - break; } } if (!tagcache_is_usable()) diff --git a/apps/tagcache.c b/apps/tagcache.c index a899ff91fd..efa615675e 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -2617,6 +2617,7 @@ static bool commit(void) logf("tagcache committed"); remove(TAGCACHE_FILE_TEMP); tc_stat.ready = check_all_headers(); + tc_stat.readyvalid = true; if (local_allocation) { @@ -3770,6 +3771,7 @@ static void tagcache_thread(void) /* Don't delay bootup with the header check but do it on background. */ sleep(HZ); tc_stat.ready = check_all_headers(); + tc_stat.readyvalid = true; while (1) { @@ -3972,6 +3974,6 @@ int tagcache_get_commit_step(void) } int tagcache_get_max_commit_step(void) { - return 8; /* To be written, better hard-coded here than in the UI */ + return (int)(sizeof(sorted_tags)/sizeof(sorted_tags[0]))+1; } diff --git a/apps/tagcache.h b/apps/tagcache.h index c8d52308ce..0cfdedf310 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -86,6 +86,7 @@ enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq, struct tagcache_stat { bool initialized; /* Is tagcache currently busy? */ + bool readyvalid; /* Has tagcache ready status been ascertained */ bool ready; /* Is tagcache ready to be used? */ bool ramcache; /* Is tagcache loaded in ram? */ bool commit_delayed; /* Has commit been delayed until next reboot? */