summaryrefslogtreecommitdiff
path: root/apps
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
parent0b9c57d33e59a26b1f341632b990aff0dffd0fcb (diff)
downloadrockbox-af7aaae478b5c7382ae5505abab233a97aa3e658.zip
rockbox-af7aaae478b5c7382ae5505abab233a97aa3e658.tar.gz
rockbox-af7aaae478b5c7382ae5505abab233a97aa3e658.tar.bz2
rockbox-af7aaae478b5c7382ae5505abab233a97aa3e658.tar.xz
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.c19
-rw-r--r--apps/playlist.h2
-rw-r--r--apps/tagcache.c57
3 files changed, 27 insertions, 51 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index dcf2fe1..ea183d7 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -575,7 +575,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist,
playlist->indices[ playlist->amount ] = i+count;
#ifdef HAVE_DIRCACHE
if (playlist->filenames)
- playlist->filenames[ playlist->amount ] = NULL;
+ playlist->filenames[ playlist->amount ] = -1;
#endif
playlist->amount++;
}
@@ -816,7 +816,7 @@ static int add_track_to_playlist(struct playlist_info* playlist,
#ifdef HAVE_DIRCACHE
if (playlist->filenames)
- playlist->filenames[insert_position] = NULL;
+ playlist->filenames[insert_position] = -1;
#endif
playlist->amount++;
@@ -958,9 +958,9 @@ static int randomise_playlist(struct playlist_info* playlist,
#ifdef HAVE_DIRCACHE
if (playlist->filenames)
{
- store = (long)playlist->filenames[candidate];
+ store = playlist->filenames[candidate];
playlist->filenames[candidate] = playlist->filenames[count];
- playlist->filenames[count] = (struct dircache_entry *)store;
+ playlist->filenames[count] = store;
}
#endif
}
@@ -1298,7 +1298,7 @@ static void playlist_thread(void)
&& queue_empty(&playlist_queue); index++)
{
/* Process only pointers that are not already loaded. */
- if (playlist->filenames[index])
+ if (playlist->filenames[index] >= 0)
continue ;
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
@@ -1310,7 +1310,7 @@ static void playlist_thread(void)
break ;
/* Set the dircache entry pointer. */
- playlist->filenames[index] = dircache_get_entry_ptr(tmp);
+ playlist->filenames[index] = dircache_get_entry_id(tmp);
/* And be on background so user doesn't notice any delays. */
yield();
@@ -1351,7 +1351,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek,
#ifdef HAVE_DIRCACHE
if (dircache_is_enabled() && playlist->filenames)
{
- if (playlist->filenames[index] != NULL)
+ if (playlist->filenames[index] >= 0)
{
max = dircache_copy_path(playlist->filenames[index],
tmp_buf, sizeof(tmp_buf)-1);
@@ -2389,7 +2389,7 @@ int playlist_add(const char *filename)
playlist->indices[playlist->amount] = playlist->buffer_end_pos;
#ifdef HAVE_DIRCACHE
- playlist->filenames[playlist->amount] = NULL;
+ playlist->filenames[playlist->amount] = -1;
#endif
playlist->amount++;
@@ -2713,8 +2713,7 @@ int playlist_create_ex(struct playlist_info* playlist,
playlist->max_playlist_size = num_indices;
playlist->indices = index_buffer;
#ifdef HAVE_DIRCACHE
- playlist->filenames = (const struct dircache_entry **)
- &playlist->indices[num_indices];
+ playlist->filenames = (int*)&playlist->indices[num_indices];
#endif
playlist->buffer_size = 0;
diff --git a/apps/playlist.h b/apps/playlist.h
index 9c45769..d994f6e 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -81,7 +81,7 @@ struct playlist_info
bool control_created; /* has control file been created? */
int dirlen; /* Length of the path to the playlist file */
unsigned long *indices; /* array of indices */
- const struct dircache_entry **filenames; /* Entries from dircache */
+ int *filenames; /* Array of dircache indices */
int max_playlist_size; /* Max number of files in playlist. Mirror of
global_settings.max_files_in_playlist */
bool in_ram; /* playlist stored in ram (dirplay) */
diff --git a/apps/tagcache.c b/apps/tagcache.c
index 080f419..c5a8dcb 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -383,8 +383,9 @@ static bool do_timed_yield(void)
#endif
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
-static long find_entry_ram(const char *filename,
- const struct dircache_entry *dc)
+/* find the ramcache entry corresponding to the file indicated by
+ * filename and dc (it's corresponding dircache id). */
+static long find_entry_ram(const char *filename, int dc)
{
static long last_pos = 0;
int i;
@@ -393,10 +394,10 @@ static long find_entry_ram(const char *filename,
if (!tc_stat.ramcache)
return -1;
- if (dc == NULL)
- dc = dircache_get_entry_ptr(filename);
+ if (dc < 0)
+ dc = dircache_get_entry_id(filename);
- if (dc == NULL)
+ if (dc < 0)
{
logf("tagcache: file not found.");
return -1;
@@ -411,7 +412,7 @@ static long find_entry_ram(const char *filename,
for (; i < current_tcmh.tch.entry_count; i++)
{
- if (hdr->indices[i].tag_seek[tag_filename] == (long)dc)
+ if (hdr->indices[i].tag_seek[tag_filename] == dc)
{
last_pos = MAX(0, i - 3);
return i;
@@ -539,7 +540,7 @@ static int find_index(const char *filename)
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
if (tc_stat.ramcache && is_dircache_intact())
- idx_id = find_entry_ram(filename, NULL);
+ idx_id = find_entry_ram(filename, -1);
#endif
if (idx_id < 0)
@@ -723,8 +724,8 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE)
&& is_dircache_intact())
{
- dircache_copy_path((struct dircache_entry *)seek,
- buf, size);
+ /* for tag_filename, seek is a dircache index */
+ dircache_copy_path(seek, buf, size);
return true;
}
else
@@ -1481,8 +1482,7 @@ static bool get_next(struct tagcache_search *tcs)
if (tcs->type == tag_filename && (flag & FLAG_DIRCACHE)
&& is_dircache_intact())
{
- size_t len = dircache_copy_path((struct dircache_entry *)tcs->position,
- buf, sizeof buf);
+ size_t len = dircache_copy_path(tcs->position, buf, sizeof buf);
tcs->result_len = len + 1;
tcs->result = buf;
tcs->ramresult = false;
@@ -1599,29 +1599,6 @@ static bool update_master_header(void)
return true;
}
-#if 0
-
-void tagcache_modify(struct tagcache_search *tcs, int type, const char *text)
-{
- struct tagentry *entry;
-
- if (tcs->type != tag_title)
- return ;
-
- /* We will need reserve buffer for this. */
- if (tcs->ramcache)
- {
- struct tagfile_entry *ep;
-
- ep = (struct tagfile_entry *)&hdr->tags[tcs->type][tcs->result_seek];
- tcs->seek_list[tcs->seek_list_count];
- }
-
- entry = find_entry_ram();
-
-}
-#endif
-
void tagcache_search_finish(struct tagcache_search *tcs)
{
int i;
@@ -1677,7 +1654,7 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
return false;
/* Find the corresponding entry in tagcache. */
- idx_id = find_entry_ram(filename, NULL);
+ idx_id = find_entry_ram(filename, -1);
if (idx_id < 0)
return false;
@@ -1761,7 +1738,7 @@ static int check_if_empty(char **tag)
static void __attribute__ ((noinline)) add_tagcache(char *path,
unsigned long mtime
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
- ,const struct dircache_entry *dc
+ ,int dc
#endif
)
{
@@ -4017,7 +3994,7 @@ static bool load_tagcache(void)
if (tag == tag_filename)
{
# ifdef HAVE_DIRCACHE
- const struct dircache_entry *dc;
+ int dc;
# endif
// FIXME: This is wrong!
@@ -4064,8 +4041,8 @@ static bool load_tagcache(void)
# ifdef HAVE_DIRCACHE
if (dircache_is_enabled())
{
- dc = dircache_get_entry_ptr(buf);
- if (dc == NULL)
+ dc = dircache_get_entry_id(buf);
+ if (dc < 0)
{
logf("Entry no longer valid.");
logf("-> %s", buf);
@@ -4075,7 +4052,7 @@ static bool load_tagcache(void)
}
idx->flag |= FLAG_DIRCACHE;
- idx->tag_seek[tag_filename] = (long)dc;
+ idx->tag_seek[tag_filename] = dc;
}
else
# endif