Tagcache: Rename global static variable for better readability.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30239 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2011-08-02 14:35:10 +00:00
parent 68e066f400
commit 7bbd7daaf7

View file

@ -221,7 +221,7 @@ struct statefile_header {
# endif
/* Pointer to allocated ramcache_header */
static struct ramcache_header *hdr;
static struct ramcache_header *ramcache_hdr;
#endif
/**
@ -413,7 +413,7 @@ static long find_entry_ram(const char *filename, int dc)
for (; i < current_tcmh.tch.entry_count; i++)
{
if (hdr->indices[i].tag_seek[tag_filename] == dc)
if (ramcache_hdr->indices[i].tag_seek[tag_filename] == dc)
{
last_pos = MAX(0, i - 3);
return i;
@ -584,15 +584,15 @@ static bool get_index(int masterfd, int idxid,
#ifdef HAVE_TC_RAMCACHE
if (tc_stat.ramcache && use_ram)
{
if (hdr->indices[idxid].flag & FLAG_DELETED)
if (ramcache_hdr->indices[idxid].flag & FLAG_DELETED)
return false;
# ifdef HAVE_DIRCACHE
if (!(hdr->indices[idxid].flag & FLAG_DIRCACHE)
if (!(ramcache_hdr->indices[idxid].flag & FLAG_DIRCACHE)
|| is_dircache_intact())
#endif
{
memcpy(idx, &hdr->indices[idxid], sizeof(struct index_entry));
memcpy(idx, &ramcache_hdr->indices[idxid], sizeof(struct index_entry));
return true;
}
}
@ -649,7 +649,7 @@ static bool write_index(int masterfd, int idxid, struct index_entry *idx)
if (tc_stat.ramcache)
{
int tag;
struct index_entry *idx_ram = &hdr->indices[idxid];
struct index_entry *idx_ram = &ramcache_hdr->indices[idxid];
for (tag = 0; tag < TAG_COUNT; tag++)
{
@ -733,7 +733,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
# endif
if (tag != tag_filename)
{
ep = (struct tagfile_entry *)&hdr->tags[tag][seek];
ep = (struct tagfile_entry *)&ramcache_hdr->tags[tag][seek];
strlcpy(buf, ep->tag_data, size);
return true;
@ -1022,7 +1022,8 @@ static bool check_clauses(struct tagcache_search *tcs,
}
else
{
tfe = (struct tagfile_entry *)&hdr->tags[clause->tag][seek];
tfe = (struct tagfile_entry *)
&ramcache_hdr->tags[clause->tag][seek];
str = tfe->tag_data;
}
}
@ -1140,7 +1141,7 @@ static bool build_lookup_list(struct tagcache_search *tcs)
for (i = tcs->seek_pos; i < current_tcmh.tch.entry_count; i++)
{
struct tagcache_seeklist_entry *seeklist;
struct index_entry *idx = &hdr->indices[i];
struct index_entry *idx = &ramcache_hdr->indices[i];
if (tcs->seek_list_count == SEEK_LIST_SIZE)
break ;
@ -1326,7 +1327,7 @@ bool tagcache_search(struct tagcache_search *tcs, int tag)
tcs->ramsearch = tc_stat.ramcache;
if (tcs->ramsearch)
{
tcs->entry_count = hdr->entry_count[tcs->type];
tcs->entry_count = ramcache_hdr->entry_count[tcs->type];
}
else
#endif
@ -1512,7 +1513,7 @@ static bool get_next(struct tagcache_search *tcs)
{
struct tagfile_entry *ep;
ep = (struct tagfile_entry *)&hdr->tags[tcs->type][tcs->position];
ep = (struct tagfile_entry *)&ramcache_hdr->tags[tcs->type][tcs->position];
tcs->result = ep->tag_data;
tcs->result_len = strlen(tcs->result) + 1;
tcs->idx_id = ep->idx_id;
@ -1648,7 +1649,7 @@ void tagcache_search_finish(struct tagcache_search *tcs)
#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
static struct tagfile_entry *get_tag(const struct index_entry *entry, int tag)
{
return (struct tagfile_entry *)&hdr->tags[tag][entry->tag_seek[tag]];
return (struct tagfile_entry *)&ramcache_hdr->tags[tag][entry->tag_seek[tag]];
}
static long get_tag_numeric(const struct index_entry *entry, int tag, int idx_id)
@ -1675,7 +1676,7 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename)
if (idx_id < 0)
return false;
entry = &hdr->indices[idx_id];
entry = &ramcache_hdr->indices[idx_id];
memset(id3, 0, sizeof(struct mp3entry));
@ -2951,7 +2952,7 @@ static bool commit(void)
#ifdef HAVE_TC_RAMCACHE
if (tempbuf_size == 0 && tc_stat.ramcache_allocated > 0)
{
tempbuf = (char *)(hdr + 1);
tempbuf = (char *)(ramcache_hdr + 1);
tempbuf_size = tc_stat.ramcache_allocated - sizeof(struct ramcache_header) - 128;
tempbuf_size &= ~0x03;
}
@ -3581,7 +3582,7 @@ static bool delete_entry(long idx_id)
#ifdef HAVE_TC_RAMCACHE
/* At first mark the entry removed from ram cache. */
if (tc_stat.ramcache)
hdr->indices[idx_id].flag |= FLAG_DELETED;
ramcache_hdr->indices[idx_id].flag |= FLAG_DELETED;
#endif
if ( (masterfd = open_master_fd(&myhdr, true) ) < 0)
@ -3620,7 +3621,7 @@ static bool delete_entry(long idx_id)
#ifdef HAVE_TC_RAMCACHE
/* Use RAM DB if available for greater speed */
if (tc_stat.ramcache)
idxp = &hdr->indices[i];
idxp = &ramcache_hdr->indices[i];
else
#endif
{
@ -3663,9 +3664,9 @@ static bool delete_entry(long idx_id)
if (tc_stat.ramcache && tag != tag_filename)
{
struct tagfile_entry *tfe;
int32_t *seek = &hdr->indices[idx_id].tag_seek[tag];
int32_t *seek = &ramcache_hdr->indices[idx_id].tag_seek[tag];
tfe = (struct tagfile_entry *)&hdr->tags[tag][*seek];
tfe = (struct tagfile_entry *)&ramcache_hdr->tags[tag][*seek];
*seek = crc_32(tfe->tag_data, strlen(tfe->tag_data), 0xffffffff);
myidx.tag_seek[tag] = *seek;
}
@ -3710,7 +3711,8 @@ static bool delete_entry(long idx_id)
/* Delete from ram. */
if (tc_stat.ramcache && tag != tag_filename)
{
struct tagfile_entry *tagentry = (struct tagfile_entry *)&hdr->tags[tag][oldseek];
struct tagfile_entry *tagentry =
(struct tagfile_entry *)&ramcache_hdr->tags[tag][oldseek];
tagentry->tag_data[0] = '\0';
}
#endif
@ -3795,7 +3797,7 @@ static bool allocate_tagcache(void)
/* Load the header. */
if ( (fd = open_master_fd(&tcmh, false)) < 0)
{
hdr = NULL;
ramcache_hdr = NULL;
return false;
}
@ -3807,8 +3809,8 @@ static bool allocate_tagcache(void)
*/
tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE +
sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *);
hdr = buffer_alloc(tc_stat.ramcache_allocated + 128);
memset(hdr, 0, sizeof(struct ramcache_header));
ramcache_hdr = buffer_alloc(tc_stat.ramcache_allocated + 128);
memset(ramcache_hdr, 0, sizeof(struct ramcache_header));
memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated);
@ -3831,29 +3833,29 @@ static bool tagcache_dumpload(void)
}
/* Check the statefile memory placement */
hdr = buffer_alloc(0);
ramcache_hdr = buffer_alloc(0);
rc = read(fd, &shdr, sizeof(struct statefile_header));
if (rc != sizeof(struct statefile_header)
|| shdr.magic != TAGCACHE_STATEFILE_MAGIC
|| shdr.mh.tch.magic != TAGCACHE_MAGIC)
{
logf("incorrect statefile");
hdr = NULL;
ramcache_hdr = NULL;
close(fd);
return false;
}
offpos = (long)hdr - (long)shdr.hdr;
offpos = (long)ramcache_hdr - (long)shdr.hdr;
/* Lets allocate real memory and load it */
hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated);
rc = read(fd, hdr, shdr.tc_stat.ramcache_allocated);
ramcache_hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated);
rc = read(fd, ramcache_hdr, shdr.tc_stat.ramcache_allocated);
close(fd);
if (rc != shdr.tc_stat.ramcache_allocated)
{
logf("read failure!");
hdr = NULL;
ramcache_hdr = NULL;
return false;
}
@ -3861,7 +3863,7 @@ static bool tagcache_dumpload(void)
/* Now fix the pointers */
for (i = 0; i < TAG_COUNT; i++)
hdr->tags[i] += offpos;
ramcache_hdr->tags[i] += offpos;
/* Load the tagcache master header (should match the actual DB file header). */
memcpy(&current_tcmh, &shdr.mh, sizeof current_tcmh);
@ -3886,13 +3888,13 @@ static bool tagcache_dumpsave(void)
/* Create the header */
shdr.magic = TAGCACHE_STATEFILE_MAGIC;
shdr.hdr = hdr;
shdr.hdr = ramcache_hdr;
memcpy(&shdr.mh, &current_tcmh, sizeof current_tcmh);
memcpy(&shdr.tc_stat, &tc_stat, sizeof tc_stat);
write(fd, &shdr, sizeof shdr);
/* And dump the data too */
write(fd, hdr, tc_stat.ramcache_allocated);
write(fd, ramcache_hdr, tc_stat.ramcache_allocated);
close(fd);
return true;
@ -3936,7 +3938,7 @@ static bool load_tagcache(void)
/* Master header copy should already match, this can be redundant to do. */
memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
idx = hdr->indices;
idx = ramcache_hdr->indices;
/* Load the master index table. */
for (i = 0; i < tcmh.tch.entry_count; i++)
@ -3952,7 +3954,8 @@ static bool load_tagcache(void)
}
bytesleft -= sizeof(struct index_entry);
if (bytesleft < 0 || ((long)idx - (long)hdr->indices) >= tc_stat.ramcache_allocated)
if (bytesleft < 0 ||
((long)idx - (long)ramcache_hdr->indices) >= tc_stat.ramcache_allocated)
{
logf("too big tagcache.");
close(fd);
@ -3976,7 +3979,7 @@ static bool load_tagcache(void)
//p = ((void *)p+1);
p = (char *)((long)p & ~0x03) + 0x04;
hdr->tags[tag] = p;
ramcache_hdr->tags[tag] = p;
/* Check the header. */
tch = (struct tagcache_header *)p;
@ -3985,9 +3988,9 @@ static bool load_tagcache(void)
if ( (fd = open_tag_fd(tch, tag, false)) < 0)
return false;
for (hdr->entry_count[tag] = 0;
hdr->entry_count[tag] < tch->entry_count;
hdr->entry_count[tag]++)
for (ramcache_hdr->entry_count[tag] = 0;
ramcache_hdr->entry_count[tag] < tch->entry_count;
ramcache_hdr->entry_count[tag]++)
{
long pos;
@ -4016,7 +4019,7 @@ static bool load_tagcache(void)
int dc;
# endif
idx = &hdr->indices[fe->idx_id];
idx = &ramcache_hdr->indices[fe->idx_id];
if (fe->tag_length >= (long)sizeof(buf)-1)
{
@ -4477,7 +4480,7 @@ void tagcache_build(const char *path)
#endif
#ifdef HAVE_TC_RAMCACHE
if (hdr)
if (ramcache_hdr)
{
/* Import runtime statistics if we just initialized the db. */
if (current_tcmh.serial == 0)
@ -4491,7 +4494,7 @@ void tagcache_build(const char *path)
#ifdef HAVE_TC_RAMCACHE
static void load_ramcache(void)
{
if (!hdr)
if (!ramcache_hdr)
return ;
cpu_boost(true);
@ -4504,7 +4507,7 @@ static void load_ramcache(void)
/* If loading failed, it must indicate some problem with the db
* so disable it entirely to prevent further issues. */
tc_stat.ready = false;
hdr = NULL;
ramcache_hdr = NULL;
}
cpu_boost(false);
@ -4667,7 +4670,7 @@ static int get_progress(void)
#endif
#ifdef HAVE_TC_RAMCACHE
{
if (hdr && tc_stat.ramcache)
if (ramcache_hdr && tc_stat.ramcache)
total_count = current_tcmh.tch.entry_count;
}
#endif