Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

[BugFix] playlist.c DIRCACHE stop scanning when changing indices

dc_playlist_thread may continue loading pointers even while
underlying indices are changing instead stop the loop by marking
pointers as clean and rebuild later

Change-Id: If154f673b4af8d6e9c364499d58f1321834a76a4

authored by

William Wilgus and committed by
William Wilgus
00c7817c 16a32c57

+48 -7
+48 -7
apps/playlist.c
··· 172 172 173 173 #ifdef HAVE_DIRCACHE 174 174 #define PLAYLIST_LOAD_POINTERS 1 175 + #define PLAYLIST_CLEAN_POINTERS 2 176 + static bool dc_has_dirty_pointers = false; 175 177 176 178 static struct event_queue playlist_queue SHAREDBSS_ATTR; 177 179 static long playlist_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; ··· 217 219 { 218 220 #ifdef HAVE_DIRCACHE 219 221 queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0); 222 + #endif 223 + /* No-Op for non dircache targets */ 224 + } 225 + 226 + static void dc_discard_playlist_pointers(void) 227 + { 228 + #ifdef HAVE_DIRCACHE 229 + /* dump any pointers currently waiting */ 230 + if (dc_has_dirty_pointers) 231 + queue_send(&playlist_queue, PLAYLIST_CLEAN_POINTERS, 0); 220 232 #endif 221 233 /* No-Op for non dircache targets */ 222 234 } ··· 494 506 */ 495 507 static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume) 496 508 { 509 + dc_discard_playlist_pointers(); 497 510 498 511 if(playlist->fd >= 0) /* If there is an already open playlist, close it. */ 499 512 { ··· 884 897 exit: 885 898 886 899 playlist_mutex_unlock(&(playlist->mutex)); 887 - dc_load_playlist_pointers(); 888 900 889 901 return result; 890 902 } ··· 1512 1524 return -1; 1513 1525 1514 1526 playlist_mutex_lock(&(playlist->mutex)); 1527 + 1515 1528 inserted = playlist->indices[position] & PLAYLIST_INSERT_TYPE_MASK; 1516 1529 1517 1530 /* shift indices now that track has been removed */ ··· 1589 1602 unsigned int current = playlist->indices[playlist->index]; 1590 1603 1591 1604 playlist_mutex_lock(&(playlist->mutex)); 1605 + 1606 + dc_discard_playlist_pointers(); 1592 1607 1593 1608 /* seed 0 is used to identify sorted playlist for resume purposes */ 1594 1609 if (seed == 0) ··· 1673 1688 static int sort_playlist_unlocked(struct playlist_info* playlist, 1674 1689 bool start_current, bool write) 1675 1690 { 1691 + unsigned int current = playlist->indices[playlist->index]; 1676 1692 1677 - unsigned int current = playlist->indices[playlist->index]; 1693 + dc_discard_playlist_pointers(); 1678 1694 1679 1695 if (playlist->amount > 0) 1680 1696 qsort((void*)playlist->indices, playlist->amount, ··· 1875 1891 static void dc_thread_playlist(void) 1876 1892 { 1877 1893 struct queue_event ev; 1878 - bool dirty_pointers = false; 1879 1894 static char tmp[MAX_PATH+1]; 1880 1895 1881 1896 struct playlist_info *playlist; ··· 1897 1912 1898 1913 switch (ev.id) 1899 1914 { 1915 + case PLAYLIST_CLEAN_POINTERS: 1916 + dc_has_dirty_pointers = false; 1917 + queue_reply(&playlist_queue, 0); 1918 + break; 1919 + 1900 1920 case PLAYLIST_LOAD_POINTERS: 1901 - dirty_pointers = true; 1921 + dc_has_dirty_pointers = true; 1902 1922 break ; 1903 1923 1904 1924 /* Start the background scanning after either the disk spindown ··· 1916 1936 break ; 1917 1937 1918 1938 /* Check if previously loaded pointers are intact. */ 1919 - if (!dirty_pointers) 1939 + if (!dc_has_dirty_pointers) 1920 1940 break ; 1921 1941 1922 1942 struct dircache_info info; ··· 1955 1975 cancel_cpu_boost(); 1956 1976 1957 1977 if (index == playlist->amount) 1958 - dirty_pointers = false; 1978 + dc_has_dirty_pointers = false; 1959 1979 1960 1980 break ; 1961 1981 } ··· 2188 2208 new_playlist_unlocked(playlist, dir, file); 2189 2209 2190 2210 if (file) 2211 + { 2191 2212 /* load the playlist file */ 2192 2213 add_indices_to_playlist(playlist, temp_buffer, temp_buffer_size); 2193 - 2214 + dc_load_playlist_pointers(); 2215 + } 2194 2216 return 0; 2195 2217 } 2196 2218 ··· 2215 2237 buflen = ALIGN_DOWN(buflen, 512); /* to avoid partial sector I/O */ 2216 2238 /* load the playlist file */ 2217 2239 add_indices_to_playlist(playlist, buf, buflen); 2240 + dc_load_playlist_pointers(); 2218 2241 core_free(handle); 2219 2242 } 2220 2243 else ··· 2284 2307 notify_control_access_error(); 2285 2308 return -1; 2286 2309 } 2310 + 2311 + dc_discard_playlist_pointers(); 2287 2312 2288 2313 if (index == PLAYLIST_DELETE_CURRENT) 2289 2314 index = playlist->index; ··· 2570 2595 return -1; 2571 2596 } 2572 2597 2598 + dc_discard_playlist_pointers(); 2599 + 2573 2600 if (queue) 2574 2601 count_str = ID2P(LANG_PLAYLIST_QUEUE_COUNT); 2575 2602 else ··· 2622 2649 2623 2650 playlist_mutex_lock(&(playlist->mutex)); 2624 2651 2652 + dc_discard_playlist_pointers(); 2653 + 2625 2654 cpu_boost(true); 2626 2655 2627 2656 if (check_control(playlist) < 0) ··· 2750 2779 2751 2780 playlist_mutex_lock(&(playlist->mutex)); 2752 2781 2782 + dc_discard_playlist_pointers(); 2783 + 2753 2784 if (check_control(playlist) < 0) 2754 2785 { 2755 2786 notify_control_access_error(); ··· 2763 2794 * bunch of files from tagcache, syncing after every file wouldn't be 2764 2795 * a good thing to do. */ 2765 2796 if (sync && result >= 0) 2797 + { 2766 2798 playlist_sync(playlist); 2799 + } 2767 2800 2768 2801 playlist_mutex_unlock(&(playlist->mutex)); 2769 2802 ··· 2860 2893 goto out; 2861 2894 } 2862 2895 2896 + dc_discard_playlist_pointers(); 2897 + 2863 2898 /* We want to insert the track at the position that was specified by 2864 2899 new_index. This may be different then new_index because of the 2865 2900 shifting that will occur after the delete. ··· 2974 3009 && (global_settings.repeat_mode != REPEAT_ONE) ) 2975 3010 { 2976 3011 int i, j; 3012 + 3013 + dc_discard_playlist_pointers(); 2977 3014 2978 3015 /* We need to delete all the queued songs */ 2979 3016 for (i=0, j=steps; i<j; i++) ··· 3152 3189 3153 3190 if (playlist == NULL) 3154 3191 playlist = &current_playlist; 3192 + 3193 + dc_discard_playlist_pointers(); 3155 3194 3156 3195 while (playlist->index > 0) 3157 3196 if ((result = remove_track_from_playlist(playlist, 0, true)) < 0) ··· 3762 3801 close(playlist->fd); 3763 3802 playlist->fd = fd; 3764 3803 fd = -1; 3804 + dc_discard_playlist_pointers(); 3765 3805 3766 3806 if (!reparse) 3767 3807 { ··· 3787 3827 /* we need to recreate control because inserted tracks are 3788 3828 now part of the playlist and shuffle has been invalidated */ 3789 3829 result = recreate_control_unlocked(playlist); 3830 + dc_load_playlist_pointers(); 3790 3831 } 3791 3832 } 3792 3833