diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2017-02-12 07:13:25 -0500 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2017-02-13 00:46:23 -0500 |
commit | dc22522c2c21f058333e4383d644cb18f355ac76 (patch) | |
tree | 5b79ef883bb8bc86416706521362f28498b55b2f | |
parent | 0a9f71790bcad2c6ffdc96db59c446fe84336d40 (diff) | |
download | rockbox-dc22522c2c21f058333e4383d644cb18f355ac76.tar.gz rockbox-dc22522c2c21f058333e4383d644cb18f355ac76.zip |
Tweak a few tagcache things.
* Take out pointless dircache_search; nothing can be reconstructed
with the given info in find_entry_ram(); don't even try there.
Path AND index id must be known. Work it out later.
* Timed yield must be far more often than once every 1/4 second (?!)
* Do better the memory-remaining checks for ramcache load.
* Root separator mustn't be doubled up when searching files.
Change-Id: I091813f4495f3bd0d0c4672bc674df52343b3e48
-rw-r--r-- | apps/tagcache.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index dfab06da20..6b6e4839d5 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -438,8 +438,8 @@ static bool do_timed_yield(void) | |||
438 | static long wakeup_tick = 0; | 438 | static long wakeup_tick = 0; |
439 | if (TIME_AFTER(current_tick, wakeup_tick)) | 439 | if (TIME_AFTER(current_tick, wakeup_tick)) |
440 | { | 440 | { |
441 | wakeup_tick = current_tick + (HZ/4); | ||
442 | yield(); | 441 | yield(); |
442 | wakeup_tick = current_tick + (HZ/50); | ||
443 | return true; | 443 | return true; |
444 | } | 444 | } |
445 | return false; | 445 | return false; |
@@ -471,27 +471,17 @@ static long find_entry_ram(const char *filename) | |||
471 | { | 471 | { |
472 | for (int i = last_pos; i < end_pos; i++) | 472 | for (int i = last_pos; i < end_pos; i++) |
473 | { | 473 | { |
474 | if (tcramcache.hdr->indices[i].flag & FLAG_DIRCACHE) | 474 | do_timed_yield(); |
475 | { | ||
476 | int cmp = dircache_fileref_cmp(&tcrc_dcfrefs[i], &dcfref); | ||
477 | if (cmp > 0) | ||
478 | { | ||
479 | if (cmp < 3) | ||
480 | { | ||
481 | if (dircache_search(DCS_CACHED_PATH | DCS_UPDATE_FILEREF, | ||
482 | &dcfref, filename) <= 0) | ||
483 | return -1; | ||
484 | 475 | ||
485 | if (dircache_fileref_cmp(&tcrc_dcfrefs[i], &dcfref) < 3) | 476 | if (!(tcramcache.hdr->indices[i].flag & FLAG_DIRCACHE)) |
486 | return -1; | 477 | continue; |
487 | } | ||
488 | 478 | ||
489 | last_pos = MAX(0, i - 3); | 479 | int cmp = dircache_fileref_cmp(&tcrc_dcfrefs[i], &dcfref); |
490 | return i; | 480 | if (cmp < 3) |
491 | } | 481 | continue; |
492 | } | ||
493 | 482 | ||
494 | do_timed_yield(); | 483 | last_pos = MAX(0, i - 3); |
484 | return i; | ||
495 | } | 485 | } |
496 | 486 | ||
497 | if (last_pos == 0) | 487 | if (last_pos == 0) |
@@ -4084,7 +4074,7 @@ static bool load_tagcache(void) | |||
4084 | 4074 | ||
4085 | p = TC_ALIGN_PTR(p, &rc); | 4075 | p = TC_ALIGN_PTR(p, &rc); |
4086 | bytesleft -= rc; | 4076 | bytesleft -= rc; |
4087 | if (bytesleft <= 0) | 4077 | if (bytesleft < (ssize_t)sizeof(struct tagcache_header)) |
4088 | { | 4078 | { |
4089 | logf("Too big tagcache #10.5"); | 4079 | logf("Too big tagcache #10.5"); |
4090 | goto failure; | 4080 | goto failure; |
@@ -4112,17 +4102,11 @@ static bool load_tagcache(void) | |||
4112 | 4102 | ||
4113 | p = TC_ALIGN_PTR(p, &rc); | 4103 | p = TC_ALIGN_PTR(p, &rc); |
4114 | bytesleft -= rc; | 4104 | bytesleft -= rc; |
4115 | if (bytesleft <= 0) | 4105 | if (bytesleft < (ssize_t)sizeof(struct tagfile_entry)) |
4116 | { | 4106 | { |
4117 | logf("Too big tagcache #10.75"); | 4107 | logf("Too big tagcache #10.75"); |
4118 | goto failure; | 4108 | goto failure; |
4119 | } | 4109 | } |
4120 | |||
4121 | if (bytesleft < (ssize_t)sizeof (struct tagfile_entry)) | ||
4122 | { | ||
4123 | logf("Too big tagcache #10.875"); | ||
4124 | goto failure; | ||
4125 | } | ||
4126 | 4110 | ||
4127 | struct tagfile_entry *fe = (struct tagfile_entry *)p; | 4111 | struct tagfile_entry *fe = (struct tagfile_entry *)p; |
4128 | off_t pos = lseek(fd, 0, SEEK_CUR); | 4112 | off_t pos = lseek(fd, 0, SEEK_CUR); |
@@ -4141,6 +4125,12 @@ static bool load_tagcache(void) | |||
4141 | if (tag == tag_filename) | 4125 | if (tag == tag_filename) |
4142 | { | 4126 | { |
4143 | int idx_id = fe->idx_id; /* gonna clobber tagfile entry */ | 4127 | int idx_id = fe->idx_id; /* gonna clobber tagfile entry */ |
4128 | if (idx_id < 0 || idx_id >= tcmh.tch.entry_count) | ||
4129 | { | ||
4130 | logf("corrupt tagfile entry (tag: %d)", tag); | ||
4131 | goto failure; | ||
4132 | } | ||
4133 | |||
4144 | struct index_entry *idx = &tcramcache.hdr->indices[idx_id]; | 4134 | struct index_entry *idx = &tcramcache.hdr->indices[idx_id]; |
4145 | 4135 | ||
4146 | #ifdef HAVE_DIRCACHE | 4136 | #ifdef HAVE_DIRCACHE |
@@ -4479,7 +4469,7 @@ static bool check_dir(const char *dirname, int add_files) | |||
4479 | 4469 | ||
4480 | struct dirinfo info = dir_get_info(dir, entry); | 4470 | struct dirinfo info = dir_get_info(dir, entry); |
4481 | size_t len = strlen(curpath); | 4471 | size_t len = strlen(curpath); |
4482 | path_append(&curpath[len], PA_SEP_HARD, entry->d_name, | 4472 | path_append(&curpath[len-1], PA_SEP_HARD, entry->d_name, |
4483 | sizeof (curpath) - len); | 4473 | sizeof (curpath) - len); |
4484 | 4474 | ||
4485 | processed_dir_count++; | 4475 | processed_dir_count++; |