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
This commit is contained in:
Steve Bavin 2007-03-08 08:20:30 +00:00
parent b1646abc18
commit 149bc03d86
3 changed files with 35 additions and 29 deletions

View file

@ -104,35 +104,17 @@ static int browser(void* param)
case GO_TO_DBBROWSER: case GO_TO_DBBROWSER:
if (!tagcache_is_usable()) if (!tagcache_is_usable())
{ {
/* Check if we're still initialising, so status is unknown */ bool reinit_attempted = false;
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();
}
/* Now display progress until it's ready or the user exits */ /* Now display progress until it's ready or the user exits */
while(!tagcache_is_usable()) while(!tagcache_is_usable())
{ {
gui_syncstatusbar_draw(&statusbars, false); 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 */ /* Maybe just needs to reboot due to delayed commit */
if (stat->commit_delayed) if (stat->commit_delayed)
@ -141,6 +123,31 @@ static int browser(void* param)
break; 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 */ /* Display building progress */
if (stat->commit_step > 0) if (stat->commit_step > 0)
{ {
@ -153,10 +160,6 @@ static int browser(void* param)
gui_syncsplash(0, true, str(LANG_BUILDING_DATABASE), gui_syncsplash(0, true, str(LANG_BUILDING_DATABASE),
stat->processed_entries); stat->processed_entries);
} }
/* Allow user to exit */
if (action_userabort(HZ/2))
break;
} }
} }
if (!tagcache_is_usable()) if (!tagcache_is_usable())

View file

@ -2617,6 +2617,7 @@ static bool commit(void)
logf("tagcache committed"); logf("tagcache committed");
remove(TAGCACHE_FILE_TEMP); remove(TAGCACHE_FILE_TEMP);
tc_stat.ready = check_all_headers(); tc_stat.ready = check_all_headers();
tc_stat.readyvalid = true;
if (local_allocation) 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. */ /* Don't delay bootup with the header check but do it on background. */
sleep(HZ); sleep(HZ);
tc_stat.ready = check_all_headers(); tc_stat.ready = check_all_headers();
tc_stat.readyvalid = true;
while (1) while (1)
{ {
@ -3972,6 +3974,6 @@ int tagcache_get_commit_step(void)
} }
int tagcache_get_max_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;
} }

View file

@ -86,6 +86,7 @@ enum clause { clause_none, clause_is, clause_is_not, clause_gt, clause_gteq,
struct tagcache_stat { struct tagcache_stat {
bool initialized; /* Is tagcache currently busy? */ bool initialized; /* Is tagcache currently busy? */
bool readyvalid; /* Has tagcache ready status been ascertained */
bool ready; /* Is tagcache ready to be used? */ bool ready; /* Is tagcache ready to be used? */
bool ramcache; /* Is tagcache loaded in ram? */ bool ramcache; /* Is tagcache loaded in ram? */
bool commit_delayed; /* Has commit been delayed until next reboot? */ bool commit_delayed; /* Has commit been delayed until next reboot? */