summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-06-20 20:12:42 +0000
committerThomas Martitz <kugel@rockbox.org>2011-06-20 20:12:42 +0000
commitaf7aaae478b5c7382ae5505abab233a97aa3e658 (patch)
tree566d2e728aefb9f0e6b19edfd3519bf2826339e3 /apps/tagcache.c
parent0b9c57d33e59a26b1f341632b990aff0dffd0fcb (diff)
downloadrockbox-af7aaae478b5c7382ae5505abab233a97aa3e658.tar.gz
rockbox-af7aaae478b5c7382ae5505abab233a97aa3e658.zip
Dircache: Don't expose struct dircache_entry and pointers into the cache, use IDs instead.
Only integer IDs are exposed from dircache with this. This way the cache is isolated from other modules. This is needed for my buflib gsoc project. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30038 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c57
1 files changed, 17 insertions, 40 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 080f4198c3..c5a8dcbae5 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -383,8 +383,9 @@ static bool do_timed_yield(void)
383#endif 383#endif
384 384
385#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) 385#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
386static long find_entry_ram(const char *filename, 386/* find the ramcache entry corresponding to the file indicated by
387 const struct dircache_entry *dc) 387 * filename and dc (it's corresponding dircache id). */
388static long find_entry_ram(const char *filename, int dc)
388{ 389{
389 static long last_pos = 0; 390 static long last_pos = 0;
390 int i; 391 int i;
@@ -393,10 +394,10 @@ static long find_entry_ram(const char *filename,
393 if (!tc_stat.ramcache) 394 if (!tc_stat.ramcache)
394 return -1; 395 return -1;
395 396
396 if (dc == NULL) 397 if (dc < 0)
397 dc = dircache_get_entry_ptr(filename); 398 dc = dircache_get_entry_id(filename);
398 399
399 if (dc == NULL) 400 if (dc < 0)
400 { 401 {
401 logf("tagcache: file not found."); 402 logf("tagcache: file not found.");
402 return -1; 403 return -1;
@@ -411,7 +412,7 @@ static long find_entry_ram(const char *filename,
411 412
412 for (; i < current_tcmh.tch.entry_count; i++) 413 for (; i < current_tcmh.tch.entry_count; i++)
413 { 414 {
414 if (hdr->indices[i].tag_seek[tag_filename] == (long)dc) 415 if (hdr->indices[i].tag_seek[tag_filename] == dc)
415 { 416 {
416 last_pos = MAX(0, i - 3); 417 last_pos = MAX(0, i - 3);
417 return i; 418 return i;
@@ -539,7 +540,7 @@ static int find_index(const char *filename)
539 540
540#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) 541#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
541 if (tc_stat.ramcache && is_dircache_intact()) 542 if (tc_stat.ramcache && is_dircache_intact())
542 idx_id = find_entry_ram(filename, NULL); 543 idx_id = find_entry_ram(filename, -1);
543#endif 544#endif
544 545
545 if (idx_id < 0) 546 if (idx_id < 0)
@@ -723,8 +724,8 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
723 if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE) 724 if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE)
724 && is_dircache_intact()) 725 && is_dircache_intact())
725 { 726 {
726 dircache_copy_path((struct dircache_entry *)seek, 727 /* for tag_filename, seek is a dircache index */
727 buf, size); 728 dircache_copy_path(seek, buf, size);
728 return true; 729 return true;
729 } 730 }
730 else 731 else
@@ -1481,8 +1482,7 @@ static bool get_next(struct tagcache_search *tcs)
1481 if (tcs->type == tag_filename && (flag & FLAG_DIRCACHE) 1482 if (tcs->type == tag_filename && (flag & FLAG_DIRCACHE)
1482 && is_dircache_intact()) 1483 && is_dircache_intact())
1483 { 1484 {
1484 size_t len = dircache_copy_path((struct dircache_entry *)tcs->position, 1485 size_t len = dircache_copy_path(tcs->position, buf, sizeof buf);
1485 buf, sizeof buf);
1486 tcs->result_len = len + 1; 1486 tcs->result_len = len + 1;
1487 tcs->result = buf; 1487 tcs->result = buf;
1488 tcs->ramresult = false; 1488 tcs->ramresult = false;
@@ -1599,29 +1599,6 @@ static bool update_master_header(void)
1599 return true; 1599 return true;
1600} 1600}
1601 1601
1602#if 0
1603
1604void tagcache_modify(struct tagcache_search *tcs, int type, const char *text)
1605{
1606 struct tagentry *entry;
1607
1608 if (tcs->type != tag_title)
1609 return ;
1610
1611 /* We will need reserve buffer for this. */
1612 if (tcs->ramcache)
1613 {
1614 struct tagfile_entry *ep;
1615
1616 ep = (struct tagfile_entry *)&hdr->tags[tcs->type][tcs->result_seek];
1617 tcs->seek_list[tcs->seek_list_count];
1618 }
1619
1620 entry = find_entry_ram();
1621
1622}
1623#endif
1624
1625void tagcache_search_finish(struct tagcache_search *tcs) 1602void tagcache_search_finish(struct tagcache_search *tcs)
1626{ 1603{
1627 int i; 1604 int i;
@@ -1677,7 +1654,7 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
1677 return false; 1654 return false;
1678 1655
1679 /* Find the corresponding entry in tagcache. */ 1656 /* Find the corresponding entry in tagcache. */
1680 idx_id = find_entry_ram(filename, NULL); 1657 idx_id = find_entry_ram(filename, -1);
1681 if (idx_id < 0) 1658 if (idx_id < 0)
1682 return false; 1659 return false;
1683 1660
@@ -1761,7 +1738,7 @@ static int check_if_empty(char **tag)
1761static void __attribute__ ((noinline)) add_tagcache(char *path, 1738static void __attribute__ ((noinline)) add_tagcache(char *path,
1762 unsigned long mtime 1739 unsigned long mtime
1763#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) 1740#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
1764 ,const struct dircache_entry *dc 1741 ,int dc
1765#endif 1742#endif
1766 ) 1743 )
1767{ 1744{
@@ -4017,7 +3994,7 @@ static bool load_tagcache(void)
4017 if (tag == tag_filename) 3994 if (tag == tag_filename)
4018 { 3995 {
4019# ifdef HAVE_DIRCACHE 3996# ifdef HAVE_DIRCACHE
4020 const struct dircache_entry *dc; 3997 int dc;
4021# endif 3998# endif
4022 3999
4023 // FIXME: This is wrong! 4000 // FIXME: This is wrong!
@@ -4064,8 +4041,8 @@ static bool load_tagcache(void)
4064# ifdef HAVE_DIRCACHE 4041# ifdef HAVE_DIRCACHE
4065 if (dircache_is_enabled()) 4042 if (dircache_is_enabled())
4066 { 4043 {
4067 dc = dircache_get_entry_ptr(buf); 4044 dc = dircache_get_entry_id(buf);
4068 if (dc == NULL) 4045 if (dc < 0)
4069 { 4046 {
4070 logf("Entry no longer valid."); 4047 logf("Entry no longer valid.");
4071 logf("-> %s", buf); 4048 logf("-> %s", buf);
@@ -4075,7 +4052,7 @@ static bool load_tagcache(void)
4075 } 4052 }
4076 4053
4077 idx->flag |= FLAG_DIRCACHE; 4054 idx->flag |= FLAG_DIRCACHE;
4078 idx->tag_seek[tag_filename] = (long)dc; 4055 idx->tag_seek[tag_filename] = dc;
4079 } 4056 }
4080 else 4057 else
4081# endif 4058# endif