diff options
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 19cee60993..e95c5e5650 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -494,8 +494,6 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) | |||
494 | #ifdef X5_BACKLIGHT_SHUTDOWN | 494 | #ifdef X5_BACKLIGHT_SHUTDOWN |
495 | x5_backlight_shutdown(); | 495 | x5_backlight_shutdown(); |
496 | #endif | 496 | #endif |
497 | gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); | ||
498 | |||
499 | if (!tagcache_prepare_shutdown()) | 497 | if (!tagcache_prepare_shutdown()) |
500 | { | 498 | { |
501 | cancel_shutdown(); | 499 | cancel_shutdown(); |
@@ -503,6 +501,12 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) | |||
503 | return false; | 501 | return false; |
504 | } | 502 | } |
505 | 503 | ||
504 | gui_syncsplash(0, true, str(LANG_SHUTTINGDOWN)); | ||
505 | |||
506 | audio_stop(); | ||
507 | while (audio_status()) | ||
508 | sleep(1); | ||
509 | |||
506 | if (callback != NULL) | 510 | if (callback != NULL) |
507 | callback(parameter); | 511 | callback(parameter); |
508 | 512 | ||
diff --git a/apps/tagcache.c b/apps/tagcache.c index f478598dad..7da85578de 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -1164,6 +1164,7 @@ bool tagcache_retrieve(struct tagcache_search *tcs, int idxid, | |||
1164 | struct index_entry idx; | 1164 | struct index_entry idx; |
1165 | long seek; | 1165 | long seek; |
1166 | 1166 | ||
1167 | *buf = '\0'; | ||
1167 | if (!get_index(tcs->masterfd, idxid, &idx, true)) | 1168 | if (!get_index(tcs->masterfd, idxid, &idx, true)) |
1168 | return false; | 1169 | return false; |
1169 | 1170 | ||
@@ -1390,7 +1391,7 @@ static void add_tagcache(const char *path) | |||
1390 | if (!ret) | 1391 | if (!ret) |
1391 | return ; | 1392 | return ; |
1392 | 1393 | ||
1393 | // logf("-> %s", path); | 1394 | logf("-> %s", path); |
1394 | 1395 | ||
1395 | genrestr = id3_get_genre(&track.id3); | 1396 | genrestr = id3_get_genre(&track.id3); |
1396 | 1397 | ||
@@ -2328,7 +2329,6 @@ static bool commit(void) | |||
2328 | tagcache_start_scan(); | 2329 | tagcache_start_scan(); |
2329 | #endif | 2330 | #endif |
2330 | 2331 | ||
2331 | queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0); | ||
2332 | read_lock--; | 2332 | read_lock--; |
2333 | 2333 | ||
2334 | return true; | 2334 | return true; |
@@ -2594,7 +2594,7 @@ bool tagcache_import_changelog(void) | |||
2594 | struct master_header myhdr; | 2594 | struct master_header myhdr; |
2595 | struct tagcache_header tch; | 2595 | struct tagcache_header tch; |
2596 | int clfd, masterfd; | 2596 | int clfd, masterfd; |
2597 | char buf[512]; | 2597 | char buf[2048]; |
2598 | int pos = 0; | 2598 | int pos = 0; |
2599 | 2599 | ||
2600 | if (!stat.ready) | 2600 | if (!stat.ready) |
@@ -2673,7 +2673,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) | |||
2673 | { | 2673 | { |
2674 | struct master_header myhdr; | 2674 | struct master_header myhdr; |
2675 | struct index_entry idx; | 2675 | struct index_entry idx; |
2676 | char buf[256]; | 2676 | char buf[MAX_PATH]; |
2677 | char temp[32]; | 2677 | char temp[32]; |
2678 | int clfd; | 2678 | int clfd; |
2679 | int i, j; | 2679 | int i, j; |
@@ -2720,8 +2720,6 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) | |||
2720 | if (! (idx.flag & FLAG_DIRTYNUM) ) | 2720 | if (! (idx.flag & FLAG_DIRTYNUM) ) |
2721 | continue; | 2721 | continue; |
2722 | 2722 | ||
2723 | logf("Found!"); | ||
2724 | |||
2725 | /* Now retrieve all tags. */ | 2723 | /* Now retrieve all tags. */ |
2726 | for (j = 0; j < TAG_COUNT; j++) | 2724 | for (j = 0; j < TAG_COUNT; j++) |
2727 | { | 2725 | { |
@@ -2734,7 +2732,6 @@ bool tagcache_create_changelog(struct tagcache_search *tcs) | |||
2734 | 2732 | ||
2735 | tcs->type = j; | 2733 | tcs->type = j; |
2736 | tagcache_retrieve(tcs, i, buf, sizeof buf); | 2734 | tagcache_retrieve(tcs, i, buf, sizeof buf); |
2737 | logf("tag: %s", buf); | ||
2738 | write_tag(clfd, tagcache_tag_to_str(j), buf); | 2735 | write_tag(clfd, tagcache_tag_to_str(j), buf); |
2739 | } | 2736 | } |
2740 | 2737 | ||
@@ -2965,6 +2962,28 @@ static bool tagcache_dumpsave(void) | |||
2965 | } | 2962 | } |
2966 | # endif | 2963 | # endif |
2967 | 2964 | ||
2965 | /** | ||
2966 | * Returns true if there is an event waiting in the queue | ||
2967 | * that requires the current operation to be aborted. | ||
2968 | */ | ||
2969 | static bool check_event_queue(void) | ||
2970 | { | ||
2971 | struct event ev; | ||
2972 | |||
2973 | queue_wait_w_tmo(&tagcache_queue, &ev, 0); | ||
2974 | switch (ev.id) | ||
2975 | { | ||
2976 | case Q_STOP_SCAN: | ||
2977 | case SYS_POWEROFF: | ||
2978 | case SYS_USB_CONNECTED: | ||
2979 | /* Put the event back into the queue. */ | ||
2980 | queue_post(&tagcache_queue, ev.id, ev.data); | ||
2981 | return true; | ||
2982 | } | ||
2983 | |||
2984 | return false; | ||
2985 | } | ||
2986 | |||
2968 | static bool load_tagcache(void) | 2987 | static bool load_tagcache(void) |
2969 | { | 2988 | { |
2970 | struct tagcache_header *tch; | 2989 | struct tagcache_header *tch; |
@@ -2973,14 +2992,15 @@ static bool load_tagcache(void) | |||
2973 | int rc, fd; | 2992 | int rc, fd; |
2974 | char *p; | 2993 | char *p; |
2975 | int i, tag; | 2994 | int i, tag; |
2995 | int yield_count = 0; | ||
2976 | 2996 | ||
2977 | logf("loading tagcache to ram..."); | ||
2978 | |||
2979 | # ifdef HAVE_DIRCACHE | 2997 | # ifdef HAVE_DIRCACHE |
2980 | while (dircache_is_initializing()) | 2998 | while (dircache_is_initializing()) |
2981 | sleep(1); | 2999 | sleep(1); |
2982 | # endif | 3000 | # endif |
2983 | 3001 | ||
3002 | logf("loading tagcache to ram..."); | ||
3003 | |||
2984 | fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); | 3004 | fd = open(TAGCACHE_FILE_MASTER, O_RDONLY); |
2985 | if (fd < 0) | 3005 | if (fd < 0) |
2986 | { | 3006 | { |
@@ -3049,7 +3069,15 @@ static bool load_tagcache(void) | |||
3049 | { | 3069 | { |
3050 | long pos; | 3070 | long pos; |
3051 | 3071 | ||
3052 | yield(); | 3072 | if (yield_count++ == 100) |
3073 | { | ||
3074 | yield(); | ||
3075 | /* Abort if we got a critical event in queue */ | ||
3076 | if (check_event_queue()) | ||
3077 | return false; | ||
3078 | yield_count = 0; | ||
3079 | } | ||
3080 | |||
3053 | fe = (struct tagfile_entry *)p; | 3081 | fe = (struct tagfile_entry *)p; |
3054 | pos = lseek(fd, 0, SEEK_CUR); | 3082 | pos = lseek(fd, 0, SEEK_CUR); |
3055 | rc = read(fd, fe, sizeof(struct tagfile_entry)); | 3083 | rc = read(fd, fe, sizeof(struct tagfile_entry)); |
@@ -3204,7 +3232,7 @@ static bool check_deleted_files(void) | |||
3204 | 3232 | ||
3205 | lseek(fd, sizeof(struct tagcache_header), SEEK_SET); | 3233 | lseek(fd, sizeof(struct tagcache_header), SEEK_SET); |
3206 | while (read(fd, &tfe, sizeof(struct tagfile_entry)) | 3234 | while (read(fd, &tfe, sizeof(struct tagfile_entry)) |
3207 | == sizeof(struct tagfile_entry) && queue_empty(&tagcache_queue)) | 3235 | == sizeof(struct tagfile_entry) && !check_event_queue()) |
3208 | { | 3236 | { |
3209 | if (tfe.tag_length >= (long)sizeof(buf)-1) | 3237 | if (tfe.tag_length >= (long)sizeof(buf)-1) |
3210 | { | 3238 | { |
@@ -3252,7 +3280,7 @@ static bool check_dir(const char *dirname) | |||
3252 | } | 3280 | } |
3253 | 3281 | ||
3254 | /* Recursively scan the dir. */ | 3282 | /* Recursively scan the dir. */ |
3255 | while (queue_empty(&tagcache_queue)) | 3283 | while (!check_event_queue()) |
3256 | { | 3284 | { |
3257 | struct dircache_entry *entry; | 3285 | struct dircache_entry *entry; |
3258 | 3286 | ||
@@ -3302,13 +3330,13 @@ static void build_tagcache(void) | |||
3302 | total_entry_count = 0; | 3330 | total_entry_count = 0; |
3303 | processed_dir_count = 0; | 3331 | processed_dir_count = 0; |
3304 | 3332 | ||
3305 | logf("updating tagcache"); | ||
3306 | |||
3307 | #ifdef HAVE_DIRCACHE | 3333 | #ifdef HAVE_DIRCACHE |
3308 | while (dircache_is_initializing()) | 3334 | while (dircache_is_initializing()) |
3309 | sleep(1); | 3335 | sleep(1); |
3310 | #endif | 3336 | #endif |
3311 | 3337 | ||
3338 | logf("updating tagcache"); | ||
3339 | |||
3312 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); | 3340 | cachefd = open(TAGCACHE_FILE_TEMP, O_RDONLY); |
3313 | if (cachefd >= 0) | 3341 | if (cachefd >= 0) |
3314 | { | 3342 | { |
@@ -3363,6 +3391,15 @@ static void build_tagcache(void) | |||
3363 | logf("tagcache built!"); | 3391 | logf("tagcache built!"); |
3364 | } | 3392 | } |
3365 | 3393 | ||
3394 | #ifdef HAVE_TC_RAMCACHE | ||
3395 | if (hdr) | ||
3396 | { | ||
3397 | /* Import runtime statistics if we just initialized the db. */ | ||
3398 | if (hdr->h.serial == 0) | ||
3399 | queue_post(&tagcache_queue, Q_IMPORT_CHANGELOG, 0); | ||
3400 | } | ||
3401 | #endif | ||
3402 | |||
3366 | cpu_boost(false); | 3403 | cpu_boost(false); |
3367 | } | 3404 | } |
3368 | 3405 | ||
@@ -3500,7 +3537,6 @@ static void tagcache_thread(void) | |||
3500 | #endif | 3537 | #endif |
3501 | } | 3538 | } |
3502 | 3539 | ||
3503 | |||
3504 | logf("tagcache check done"); | 3540 | logf("tagcache check done"); |
3505 | 3541 | ||
3506 | check_done = true; | 3542 | check_done = true; |
@@ -3528,12 +3564,19 @@ bool tagcache_prepare_shutdown(void) | |||
3528 | if (tagcache_get_commit_step() > 0) | 3564 | if (tagcache_get_commit_step() > 0) |
3529 | return false; | 3565 | return false; |
3530 | 3566 | ||
3567 | tagcache_stop_scan(); | ||
3568 | while (read_lock || write_lock) | ||
3569 | sleep(1); | ||
3570 | |||
3571 | return true; | ||
3572 | } | ||
3573 | |||
3574 | void tagcache_shutdown(void) | ||
3575 | { | ||
3531 | #ifdef HAVE_EEPROM_SETTINGS | 3576 | #ifdef HAVE_EEPROM_SETTINGS |
3532 | if (stat.ramcache) | 3577 | if (stat.ramcache) |
3533 | tagcache_dumpsave(); | 3578 | tagcache_dumpsave(); |
3534 | #endif | 3579 | #endif |
3535 | |||
3536 | return true; | ||
3537 | } | 3580 | } |
3538 | 3581 | ||
3539 | static int get_progress(void) | 3582 | static int get_progress(void) |
diff --git a/apps/tagcache.h b/apps/tagcache.h index dd61931bcd..b639611394 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h | |||
@@ -160,6 +160,7 @@ bool tagcache_modify_numeric_entry(struct tagcache_search *tcs, | |||
160 | struct tagcache_stat* tagcache_get_stat(void); | 160 | struct tagcache_stat* tagcache_get_stat(void); |
161 | int tagcache_get_commit_step(void); | 161 | int tagcache_get_commit_step(void); |
162 | bool tagcache_prepare_shutdown(void); | 162 | bool tagcache_prepare_shutdown(void); |
163 | void tagcache_shutdown(void); | ||
163 | 164 | ||
164 | #ifdef HAVE_TC_RAMCACHE | 165 | #ifdef HAVE_TC_RAMCACHE |
165 | bool tagcache_is_ramcache(void); | 166 | bool tagcache_is_ramcache(void); |
diff --git a/apps/tree.c b/apps/tree.c index 6d18d79da3..8e155a96a0 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -1367,7 +1367,7 @@ void ft_play_filename(char *dir, char *file) | |||
1367 | /* These two functions are called by the USB and shutdown handlers */ | 1367 | /* These two functions are called by the USB and shutdown handlers */ |
1368 | void tree_flush(void) | 1368 | void tree_flush(void) |
1369 | { | 1369 | { |
1370 | tagcache_stop_scan(); | 1370 | tagcache_shutdown(); |
1371 | playlist_shutdown(); | 1371 | playlist_shutdown(); |
1372 | 1372 | ||
1373 | #ifdef HAVE_TC_RAMCACHE | 1373 | #ifdef HAVE_TC_RAMCACHE |