1
0
Fork 0
forked from len0rd/rockbox

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