diff options
| author | Miika Pekkarinen <miipekk@ihme.org> | 2006-09-23 10:29:14 +0000 |
|---|---|---|
| committer | Miika Pekkarinen <miipekk@ihme.org> | 2006-09-23 10:29:14 +0000 |
| commit | 6ee82e702c45308c2123656af6a6f0398962bd47 (patch) | |
| tree | 0dc80af8c22ca13f16edee59d2bbd54206e98705 /apps | |
| parent | cbe4427a0a2cf219a8b6578c662c5135c07d1af1 (diff) | |
| download | rockbox-6ee82e702c45308c2123656af6a6f0398962bd47.zip rockbox-6ee82e702c45308c2123656af6a6f0398962bd47.tar.gz rockbox-6ee82e702c45308c2123656af6a6f0398962bd47.tar.bz2 rockbox-6ee82e702c45308c2123656af6a6f0398962bd47.tar.xz | |
Properly shutdown audio playback early and flush system, including not
hanging tagcache. Fixed also tagcache line buffer running out when
importing a changelog with very long lines.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11030 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/misc.c | 8 | ||||
| -rw-r--r-- | apps/tagcache.c | 77 | ||||
| -rw-r--r-- | apps/tagcache.h | 1 | ||||
| -rw-r--r-- | apps/tree.c | 2 |
4 files changed, 68 insertions, 20 deletions
diff --git a/apps/misc.c b/apps/misc.c index 19cee60..e95c5e5 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -494,8 +494,6 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) #ifdef X5_BACKLIGHT_SHUTDOWN x5_backlight_shutdown(); #endif - gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); - if (!tagcache_prepare_shutdown()) { cancel_shutdown(); @@ -503,6 +501,12 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) return false; } + gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); + + audio_stop(); + while (audio_status()) + sleep(1); + if (callback != NULL) callback(parameter); diff --git a/apps/tagcache.c b/apps/tagcache.c index f478598..7da8557 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -1164,6 +1164,7 @@ bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, struct index_entry idx; long seek; + *buf = '\0'; if (!get_index(tcs->masterfd, idxid, &idx, true)) return false; @@ -1390,7 +1391,7 @@ static void add_tagcache(const char *path) if (!ret) return ; - // logf("-> %s", path); + logf("-> %s", path); genrestr = id3_get_genre(&track.id3); @@ -2328,7 +2329,6 @@ static bool commit(void) tagcache_start_scan(); #endif - queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0); read_lock--; return true; @@ -2594,7 +2594,7 @@ bool tagcache_import_changelog(void) struct master_header myhdr; struct tagcache_header tch; int clfd, masterfd; - char buf[512]; + char buf[2048]; int pos = 0; if (!stat.ready) @@ -2673,7 +2673,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) { struct master_header myhdr; struct index_entry idx; - char buf[256]; + char buf[MAX_PATH]; char temp[32]; int clfd; int i, j; @@ -2720,8 +2720,6 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) if (! (idx.flag & FLAG_DIRTYNUM) ) continue; - logf("Found!"); - /* Now retrieve all tags. */ for (j = 0; j < TAG_COUNT; j++) { @@ -2734,7 +2732,6 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) tcs->type = j; tagcache_retrieve(tcs, i, buf, sizeof buf); - logf("tag: %s", buf); write_tag(clfd, tagcache_tag_to_str(j), buf); } @@ -2965,6 +2962,28 @@ static bool tagcache_dumpsave(void) } # endif +/** + * Returns true if there is an event waiting in the queue + * that requires the current operation to be aborted. + */ +static bool check_event_queue(void) +{ + struct event ev; + + queue_wait_w_tmo(&tagcache_queue, &ev, 0); + switch (ev.id) + { + case Q_STOP_SCAN: + case SYS_POWEROFF: + case SYS_USB_CONNECTED: + /* Put the event back into the queue. */ + queue_post(&tagcache_queue, ev.id, ev.data); + return true; + } + + return false; +} + static bool load_tagcache(void) { struct tagcache_header *tch; @@ -2973,14 +2992,15 @@ static bool load_tagcache(void) int rc, fd; char *p; int i, tag; + int yield_count = 0; - logf("loading tagcache to ram..."); - # ifdef HAVE_DIRCACHE while (dircache_is_initializing()) sleep(1); # endif + logf("loading tagcache to ram..."); + fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); if (fd < 0) { @@ -3049,7 +3069,15 @@ static bool load_tagcache(void) { long pos; - yield(); + if (yield_count++ == 100) + { + yield(); + /* Abort if we got a critical event in queue */ + if (check_event_queue()) + return false; + yield_count = 0; + } + fe = (struct tagfile_entry *)p; pos = lseek(fd, 0, SEEK_CUR); rc = read(fd, fe, sizeof(struct tagfile_entry)); @@ -3204,7 +3232,7 @@ static bool check_deleted_files(void) lseek(fd, sizeof(struct tagcache_header), SEEK_SET); while (read(fd, &tfe, sizeof(struct tagfile_entry)) - == sizeof(struct tagfile_entry) && queue_empty(&tagcache_queue)) + == sizeof(struct tagfile_entry) && !check_event_queue()) { if (tfe.tag_length >= (long)sizeof(buf)-1) { @@ -3252,7 +3280,7 @@ static bool check_dir(const char *dirname) } /* Recursively scan the dir. */ - while (queue_empty(&tagcache_queue)) + while (!check_event_queue()) { struct dircache_entry *entry; @@ -3302,13 +3330,13 @@ static void build_tagcache(void) total_entry_count = 0; processed_dir_count = 0; - logf("updating tagcache"); - #ifdef HAVE_DIRCACHE while (dircache_is_initializing()) sleep(1); #endif + logf("updating tagcache"); + cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); if (cachefd >= 0) { @@ -3363,6 +3391,15 @@ static void build_tagcache(void) logf("tagcache built!"); } +#ifdef HAVE_TC_RAMCACHE + if (hdr) + { + /* Import runtime statistics if we just initialized the db. */ + if (hdr->h.serial == 0) + queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0); + } +#endif + cpu_boost(false); } @@ -3500,7 +3537,6 @@ static void tagcache_thread(void) #endif } - logf("tagcache check done"); check_done = true; @@ -3528,12 +3564,19 @@ bool tagcache_prepare_shutdown(void) if (tagcache_get_commit_step() > 0) return false; + tagcache_stop_scan(); + while (read_lock || write_lock) + sleep(1); + + return true; +} + +void tagcache_shutdown(void) +{ #ifdef HAVE_EEPROM_SETTINGS if (stat.ramcache) tagcache_dumpsave(); #endif - - return true; } static int get_progress(void) diff --git a/apps/tagcache.h b/apps/tagcache.h index dd61931..b639611 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -160,6 +160,7 @@ bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, struct tagcache_stat* tagcache_get_stat(void); int tagcache_get_commit_step(void); bool tagcache_prepare_shutdown(void); +void tagcache_shutdown(void); #ifdef HAVE_TC_RAMCACHE bool tagcache_is_ramcache(void); diff --git a/apps/tree.c b/apps/tree.c index 6d18d79..8e155a9 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -1367,7 +1367,7 @@ void ft_play_filename(char *dir, char *file) /* These two functions are called by the USB and shutdown handlers */ void tree_flush(void) { - tagcache_stop_scan(); + tagcache_shutdown(); playlist_shutdown(); #ifdef HAVE_TC_RAMCACHE |