diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-06-20 20:12:42 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-06-20 20:12:42 +0000 |
commit | af7aaae478b5c7382ae5505abab233a97aa3e658 (patch) | |
tree | 566d2e728aefb9f0e6b19edfd3519bf2826339e3 /apps | |
parent | 0b9c57d33e59a26b1f341632b990aff0dffd0fcb (diff) | |
download | rockbox-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')
-rw-r--r-- | apps/playlist.c | 19 | ||||
-rw-r--r-- | apps/playlist.h | 2 | ||||
-rw-r--r-- | apps/tagcache.c | 57 |
3 files changed, 27 insertions, 51 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index dcf2fe1118..ea183d7552 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -575,7 +575,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist, | |||
575 | playlist->indices[ playlist->amount ] = i+count; | 575 | playlist->indices[ playlist->amount ] = i+count; |
576 | #ifdef HAVE_DIRCACHE | 576 | #ifdef HAVE_DIRCACHE |
577 | if (playlist->filenames) | 577 | if (playlist->filenames) |
578 | playlist->filenames[ playlist->amount ] = NULL; | 578 | playlist->filenames[ playlist->amount ] = -1; |
579 | #endif | 579 | #endif |
580 | playlist->amount++; | 580 | playlist->amount++; |
581 | } | 581 | } |
@@ -816,7 +816,7 @@ static int add_track_to_playlist(struct playlist_info* playlist, | |||
816 | 816 | ||
817 | #ifdef HAVE_DIRCACHE | 817 | #ifdef HAVE_DIRCACHE |
818 | if (playlist->filenames) | 818 | if (playlist->filenames) |
819 | playlist->filenames[insert_position] = NULL; | 819 | playlist->filenames[insert_position] = -1; |
820 | #endif | 820 | #endif |
821 | 821 | ||
822 | playlist->amount++; | 822 | playlist->amount++; |
@@ -958,9 +958,9 @@ static int randomise_playlist(struct playlist_info* playlist, | |||
958 | #ifdef HAVE_DIRCACHE | 958 | #ifdef HAVE_DIRCACHE |
959 | if (playlist->filenames) | 959 | if (playlist->filenames) |
960 | { | 960 | { |
961 | store = (long)playlist->filenames[candidate]; | 961 | store = playlist->filenames[candidate]; |
962 | playlist->filenames[candidate] = playlist->filenames[count]; | 962 | playlist->filenames[candidate] = playlist->filenames[count]; |
963 | playlist->filenames[count] = (struct dircache_entry *)store; | 963 | playlist->filenames[count] = store; |
964 | } | 964 | } |
965 | #endif | 965 | #endif |
966 | } | 966 | } |
@@ -1298,7 +1298,7 @@ static void playlist_thread(void) | |||
1298 | && queue_empty(&playlist_queue); index++) | 1298 | && queue_empty(&playlist_queue); index++) |
1299 | { | 1299 | { |
1300 | /* Process only pointers that are not already loaded. */ | 1300 | /* Process only pointers that are not already loaded. */ |
1301 | if (playlist->filenames[index]) | 1301 | if (playlist->filenames[index] >= 0) |
1302 | continue ; | 1302 | continue ; |
1303 | 1303 | ||
1304 | control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK; | 1304 | control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK; |
@@ -1310,7 +1310,7 @@ static void playlist_thread(void) | |||
1310 | break ; | 1310 | break ; |
1311 | 1311 | ||
1312 | /* Set the dircache entry pointer. */ | 1312 | /* Set the dircache entry pointer. */ |
1313 | playlist->filenames[index] = dircache_get_entry_ptr(tmp); | 1313 | playlist->filenames[index] = dircache_get_entry_id(tmp); |
1314 | 1314 | ||
1315 | /* And be on background so user doesn't notice any delays. */ | 1315 | /* And be on background so user doesn't notice any delays. */ |
1316 | yield(); | 1316 | yield(); |
@@ -1351,7 +1351,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek, | |||
1351 | #ifdef HAVE_DIRCACHE | 1351 | #ifdef HAVE_DIRCACHE |
1352 | if (dircache_is_enabled() && playlist->filenames) | 1352 | if (dircache_is_enabled() && playlist->filenames) |
1353 | { | 1353 | { |
1354 | if (playlist->filenames[index] != NULL) | 1354 | if (playlist->filenames[index] >= 0) |
1355 | { | 1355 | { |
1356 | max = dircache_copy_path(playlist->filenames[index], | 1356 | max = dircache_copy_path(playlist->filenames[index], |
1357 | tmp_buf, sizeof(tmp_buf)-1); | 1357 | tmp_buf, sizeof(tmp_buf)-1); |
@@ -2389,7 +2389,7 @@ int playlist_add(const char *filename) | |||
2389 | 2389 | ||
2390 | playlist->indices[playlist->amount] = playlist->buffer_end_pos; | 2390 | playlist->indices[playlist->amount] = playlist->buffer_end_pos; |
2391 | #ifdef HAVE_DIRCACHE | 2391 | #ifdef HAVE_DIRCACHE |
2392 | playlist->filenames[playlist->amount] = NULL; | 2392 | playlist->filenames[playlist->amount] = -1; |
2393 | #endif | 2393 | #endif |
2394 | playlist->amount++; | 2394 | playlist->amount++; |
2395 | 2395 | ||
@@ -2713,8 +2713,7 @@ int playlist_create_ex(struct playlist_info* playlist, | |||
2713 | playlist->max_playlist_size = num_indices; | 2713 | playlist->max_playlist_size = num_indices; |
2714 | playlist->indices = index_buffer; | 2714 | playlist->indices = index_buffer; |
2715 | #ifdef HAVE_DIRCACHE | 2715 | #ifdef HAVE_DIRCACHE |
2716 | playlist->filenames = (const struct dircache_entry **) | 2716 | playlist->filenames = (int*)&playlist->indices[num_indices]; |
2717 | &playlist->indices[num_indices]; | ||
2718 | #endif | 2717 | #endif |
2719 | 2718 | ||
2720 | playlist->buffer_size = 0; | 2719 | playlist->buffer_size = 0; |
diff --git a/apps/playlist.h b/apps/playlist.h index 9c45769981..d994f6e800 100644 --- a/apps/playlist.h +++ b/apps/playlist.h | |||
@@ -81,7 +81,7 @@ struct playlist_info | |||
81 | bool control_created; /* has control file been created? */ | 81 | bool control_created; /* has control file been created? */ |
82 | int dirlen; /* Length of the path to the playlist file */ | 82 | int dirlen; /* Length of the path to the playlist file */ |
83 | unsigned long *indices; /* array of indices */ | 83 | unsigned long *indices; /* array of indices */ |
84 | const struct dircache_entry **filenames; /* Entries from dircache */ | 84 | int *filenames; /* Array of dircache indices */ |
85 | int max_playlist_size; /* Max number of files in playlist. Mirror of | 85 | int max_playlist_size; /* Max number of files in playlist. Mirror of |
86 | global_settings.max_files_in_playlist */ | 86 | global_settings.max_files_in_playlist */ |
87 | bool in_ram; /* playlist stored in ram (dirplay) */ | 87 | bool in_ram; /* playlist stored in ram (dirplay) */ |
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) |
386 | static 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). */ |
388 | static 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 | |||
1604 | void 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 | |||
1625 | void tagcache_search_finish(struct tagcache_search *tcs) | 1602 | void 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) | |||
1761 | static void __attribute__ ((noinline)) add_tagcache(char *path, | 1738 | static 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 |