summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-02 14:35:10 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-02 14:35:10 +0000
commit7bbd7daaf77aa78a1ed2fc7338841f1653d20530 (patch)
tree29b14a55a9a56bb9d8e2e676ec750062a23e454b
parent68e066f400e7fb0b19e7aec0d85f5193335a32e4 (diff)
downloadrockbox-7bbd7daaf77aa78a1ed2fc7338841f1653d20530.tar.gz
rockbox-7bbd7daaf77aa78a1ed2fc7338841f1653d20530.zip
Tagcache: Rename global static variable for better readability.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30239 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/tagcache.c87
1 files changed, 45 insertions, 42 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index e841d8e420..60d676e79e 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -221,7 +221,7 @@ struct statefile_header {
221# endif 221# endif
222 222
223/* Pointer to allocated ramcache_header */ 223/* Pointer to allocated ramcache_header */
224static struct ramcache_header *hdr; 224static struct ramcache_header *ramcache_hdr;
225#endif 225#endif
226 226
227/** 227/**
@@ -413,7 +413,7 @@ static long find_entry_ram(const char *filename, int dc)
413 413
414 for (; i < current_tcmh.tch.entry_count; i++) 414 for (; i < current_tcmh.tch.entry_count; i++)
415 { 415 {
416 if (hdr->indices[i].tag_seek[tag_filename] == dc) 416 if (ramcache_hdr->indices[i].tag_seek[tag_filename] == dc)
417 { 417 {
418 last_pos = MAX(0, i - 3); 418 last_pos = MAX(0, i - 3);
419 return i; 419 return i;
@@ -584,15 +584,15 @@ static bool get_index(int masterfd, int idxid,
584#ifdef HAVE_TC_RAMCACHE 584#ifdef HAVE_TC_RAMCACHE
585 if (tc_stat.ramcache && use_ram) 585 if (tc_stat.ramcache && use_ram)
586 { 586 {
587 if (hdr->indices[idxid].flag & FLAG_DELETED) 587 if (ramcache_hdr->indices[idxid].flag & FLAG_DELETED)
588 return false; 588 return false;
589 589
590# ifdef HAVE_DIRCACHE 590# ifdef HAVE_DIRCACHE
591 if (!(hdr->indices[idxid].flag & FLAG_DIRCACHE) 591 if (!(ramcache_hdr->indices[idxid].flag & FLAG_DIRCACHE)
592 || is_dircache_intact()) 592 || is_dircache_intact())
593#endif 593#endif
594 { 594 {
595 memcpy(idx, &hdr->indices[idxid], sizeof(struct index_entry)); 595 memcpy(idx, &ramcache_hdr->indices[idxid], sizeof(struct index_entry));
596 return true; 596 return true;
597 } 597 }
598 } 598 }
@@ -649,7 +649,7 @@ static bool write_index(int masterfd, int idxid, struct index_entry *idx)
649 if (tc_stat.ramcache) 649 if (tc_stat.ramcache)
650 { 650 {
651 int tag; 651 int tag;
652 struct index_entry *idx_ram = &hdr->indices[idxid]; 652 struct index_entry *idx_ram = &ramcache_hdr->indices[idxid];
653 653
654 for (tag = 0; tag < TAG_COUNT; tag++) 654 for (tag = 0; tag < TAG_COUNT; tag++)
655 { 655 {
@@ -733,7 +733,7 @@ static bool retrieve(struct tagcache_search *tcs, struct index_entry *idx,
733# endif 733# endif
734 if (tag != tag_filename) 734 if (tag != tag_filename)
735 { 735 {
736 ep = (struct tagfile_entry *)&hdr->tags[tag][seek]; 736 ep = (struct tagfile_entry *)&ramcache_hdr->tags[tag][seek];
737 strlcpy(buf, ep->tag_data, size); 737 strlcpy(buf, ep->tag_data, size);
738 738
739 return true; 739 return true;
@@ -1022,7 +1022,8 @@ static bool check_clauses(struct tagcache_search *tcs,
1022 } 1022 }
1023 else 1023 else
1024 { 1024 {
1025 tfe = (struct tagfile_entry *)&hdr->tags[clause->tag][seek]; 1025 tfe = (struct tagfile_entry *)
1026 &ramcache_hdr->tags[clause->tag][seek];
1026 str = tfe->tag_data; 1027 str = tfe->tag_data;
1027 } 1028 }
1028 } 1029 }
@@ -1140,7 +1141,7 @@ static bool build_lookup_list(struct tagcache_search *tcs)
1140 for (i = tcs->seek_pos; i < current_tcmh.tch.entry_count; i++) 1141 for (i = tcs->seek_pos; i < current_tcmh.tch.entry_count; i++)
1141 { 1142 {
1142 struct tagcache_seeklist_entry *seeklist; 1143 struct tagcache_seeklist_entry *seeklist;
1143 struct index_entry *idx = &hdr->indices[i]; 1144 struct index_entry *idx = &ramcache_hdr->indices[i];
1144 if (tcs->seek_list_count == SEEK_LIST_SIZE) 1145 if (tcs->seek_list_count == SEEK_LIST_SIZE)
1145 break ; 1146 break ;
1146 1147
@@ -1326,7 +1327,7 @@ bool tagcache_search(struct tagcache_search *tcs, int tag)
1326 tcs->ramsearch = tc_stat.ramcache; 1327 tcs->ramsearch = tc_stat.ramcache;
1327 if (tcs->ramsearch) 1328 if (tcs->ramsearch)
1328 { 1329 {
1329 tcs->entry_count = hdr->entry_count[tcs->type]; 1330 tcs->entry_count = ramcache_hdr->entry_count[tcs->type];
1330 } 1331 }
1331 else 1332 else
1332#endif 1333#endif
@@ -1512,7 +1513,7 @@ static bool get_next(struct tagcache_search *tcs)
1512 { 1513 {
1513 struct tagfile_entry *ep; 1514 struct tagfile_entry *ep;
1514 1515
1515 ep = (struct tagfile_entry *)&hdr->tags[tcs->type][tcs->position]; 1516 ep = (struct tagfile_entry *)&ramcache_hdr->tags[tcs->type][tcs->position];
1516 tcs->result = ep->tag_data; 1517 tcs->result = ep->tag_data;
1517 tcs->result_len = strlen(tcs->result) + 1; 1518 tcs->result_len = strlen(tcs->result) + 1;
1518 tcs->idx_id = ep->idx_id; 1519 tcs->idx_id = ep->idx_id;
@@ -1648,7 +1649,7 @@ void tagcache_search_finish(struct tagcache_search *tcs)
1648#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) 1649#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
1649static struct tagfile_entry *get_tag(const struct index_entry *entry, int tag) 1650static struct tagfile_entry *get_tag(const struct index_entry *entry, int tag)
1650{ 1651{
1651 return (struct tagfile_entry *)&hdr->tags[tag][entry->tag_seek[tag]]; 1652 return (struct tagfile_entry *)&ramcache_hdr->tags[tag][entry->tag_seek[tag]];
1652} 1653}
1653 1654
1654static long get_tag_numeric(const struct index_entry *entry, int tag, int idx_id) 1655static 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)
1675 if (idx_id < 0) 1676 if (idx_id < 0)
1676 return false; 1677 return false;
1677 1678
1678 entry = &hdr->indices[idx_id]; 1679 entry = &ramcache_hdr->indices[idx_id];
1679 1680
1680 memset(id3, 0, sizeof(struct mp3entry)); 1681 memset(id3, 0, sizeof(struct mp3entry));
1681 1682
@@ -2951,7 +2952,7 @@ static bool commit(void)
2951#ifdef HAVE_TC_RAMCACHE 2952#ifdef HAVE_TC_RAMCACHE
2952 if (tempbuf_size == 0 && tc_stat.ramcache_allocated > 0) 2953 if (tempbuf_size == 0 && tc_stat.ramcache_allocated > 0)
2953 { 2954 {
2954 tempbuf = (char *)(hdr + 1); 2955 tempbuf = (char *)(ramcache_hdr + 1);
2955 tempbuf_size = tc_stat.ramcache_allocated - sizeof(struct ramcache_header) - 128; 2956 tempbuf_size = tc_stat.ramcache_allocated - sizeof(struct ramcache_header) - 128;
2956 tempbuf_size &= ~0x03; 2957 tempbuf_size &= ~0x03;
2957 } 2958 }
@@ -3581,7 +3582,7 @@ static bool delete_entry(long idx_id)
3581#ifdef HAVE_TC_RAMCACHE 3582#ifdef HAVE_TC_RAMCACHE
3582 /* At first mark the entry removed from ram cache. */ 3583 /* At first mark the entry removed from ram cache. */
3583 if (tc_stat.ramcache) 3584 if (tc_stat.ramcache)
3584 hdr->indices[idx_id].flag |= FLAG_DELETED; 3585 ramcache_hdr->indices[idx_id].flag |= FLAG_DELETED;
3585#endif 3586#endif
3586 3587
3587 if ( (masterfd = open_master_fd(&myhdr, true) ) < 0) 3588 if ( (masterfd = open_master_fd(&myhdr, true) ) < 0)
@@ -3620,7 +3621,7 @@ static bool delete_entry(long idx_id)
3620#ifdef HAVE_TC_RAMCACHE 3621#ifdef HAVE_TC_RAMCACHE
3621 /* Use RAM DB if available for greater speed */ 3622 /* Use RAM DB if available for greater speed */
3622 if (tc_stat.ramcache) 3623 if (tc_stat.ramcache)
3623 idxp = &hdr->indices[i]; 3624 idxp = &ramcache_hdr->indices[i];
3624 else 3625 else
3625#endif 3626#endif
3626 { 3627 {
@@ -3663,9 +3664,9 @@ static bool delete_entry(long idx_id)
3663 if (tc_stat.ramcache && tag != tag_filename) 3664 if (tc_stat.ramcache && tag != tag_filename)
3664 { 3665 {
3665 struct tagfile_entry *tfe; 3666 struct tagfile_entry *tfe;
3666 int32_t *seek = &hdr->indices[idx_id].tag_seek[tag]; 3667 int32_t *seek = &ramcache_hdr->indices[idx_id].tag_seek[tag];
3667 3668
3668 tfe = (struct tagfile_entry *)&hdr->tags[tag][*seek]; 3669 tfe = (struct tagfile_entry *)&ramcache_hdr->tags[tag][*seek];
3669 *seek = crc_32(tfe->tag_data, strlen(tfe->tag_data), 0xffffffff); 3670 *seek = crc_32(tfe->tag_data, strlen(tfe->tag_data), 0xffffffff);
3670 myidx.tag_seek[tag] = *seek; 3671 myidx.tag_seek[tag] = *seek;
3671 } 3672 }
@@ -3710,7 +3711,8 @@ static bool delete_entry(long idx_id)
3710 /* Delete from ram. */ 3711 /* Delete from ram. */
3711 if (tc_stat.ramcache && tag != tag_filename) 3712 if (tc_stat.ramcache && tag != tag_filename)
3712 { 3713 {
3713 struct tagfile_entry *tagentry = (struct tagfile_entry *)&hdr->tags[tag][oldseek]; 3714 struct tagfile_entry *tagentry =
3715 (struct tagfile_entry *)&ramcache_hdr->tags[tag][oldseek];
3714 tagentry->tag_data[0] = '\0'; 3716 tagentry->tag_data[0] = '\0';
3715 } 3717 }
3716#endif 3718#endif
@@ -3795,7 +3797,7 @@ static bool allocate_tagcache(void)
3795 /* Load the header. */ 3797 /* Load the header. */
3796 if ( (fd = open_master_fd(&tcmh, false)) < 0) 3798 if ( (fd = open_master_fd(&tcmh, false)) < 0)
3797 { 3799 {
3798 hdr = NULL; 3800 ramcache_hdr = NULL;
3799 return false; 3801 return false;
3800 } 3802 }
3801 3803
@@ -3807,8 +3809,8 @@ static bool allocate_tagcache(void)
3807 */ 3809 */
3808 tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE + 3810 tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE +
3809 sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); 3811 sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *);
3810 hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); 3812 ramcache_hdr = buffer_alloc(tc_stat.ramcache_allocated + 128);
3811 memset(hdr, 0, sizeof(struct ramcache_header)); 3813 memset(ramcache_hdr, 0, sizeof(struct ramcache_header));
3812 memcpy(&current_tcmh, &tcmh, sizeof current_tcmh); 3814 memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
3813 logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); 3815 logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated);
3814 3816
@@ -3831,29 +3833,29 @@ static bool tagcache_dumpload(void)
3831 } 3833 }
3832 3834
3833 /* Check the statefile memory placement */ 3835 /* Check the statefile memory placement */
3834 hdr = buffer_alloc(0); 3836 ramcache_hdr = buffer_alloc(0);
3835 rc = read(fd, &shdr, sizeof(struct statefile_header)); 3837 rc = read(fd, &shdr, sizeof(struct statefile_header));
3836 if (rc != sizeof(struct statefile_header) 3838 if (rc != sizeof(struct statefile_header)
3837 || shdr.magic != TAGCACHE_STATEFILE_MAGIC 3839 || shdr.magic != TAGCACHE_STATEFILE_MAGIC
3838 || shdr.mh.tch.magic != TAGCACHE_MAGIC) 3840 || shdr.mh.tch.magic != TAGCACHE_MAGIC)
3839 { 3841 {
3840 logf("incorrect statefile"); 3842 logf("incorrect statefile");
3841 hdr = NULL; 3843 ramcache_hdr = NULL;
3842 close(fd); 3844 close(fd);
3843 return false; 3845 return false;
3844 } 3846 }
3845 3847
3846 offpos = (long)hdr - (long)shdr.hdr; 3848 offpos = (long)ramcache_hdr - (long)shdr.hdr;
3847 3849
3848 /* Lets allocate real memory and load it */ 3850 /* Lets allocate real memory and load it */
3849 hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated); 3851 ramcache_hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated);
3850 rc = read(fd, hdr, shdr.tc_stat.ramcache_allocated); 3852 rc = read(fd, ramcache_hdr, shdr.tc_stat.ramcache_allocated);
3851 close(fd); 3853 close(fd);
3852 3854
3853 if (rc != shdr.tc_stat.ramcache_allocated) 3855 if (rc != shdr.tc_stat.ramcache_allocated)
3854 { 3856 {
3855 logf("read failure!"); 3857 logf("read failure!");
3856 hdr = NULL; 3858 ramcache_hdr = NULL;
3857 return false; 3859 return false;
3858 } 3860 }
3859 3861
@@ -3861,7 +3863,7 @@ static bool tagcache_dumpload(void)
3861 3863
3862 /* Now fix the pointers */ 3864 /* Now fix the pointers */
3863 for (i = 0; i < TAG_COUNT; i++) 3865 for (i = 0; i < TAG_COUNT; i++)
3864 hdr->tags[i] += offpos; 3866 ramcache_hdr->tags[i] += offpos;
3865 3867
3866 /* Load the tagcache master header (should match the actual DB file header). */ 3868 /* Load the tagcache master header (should match the actual DB file header). */
3867 memcpy(&current_tcmh, &shdr.mh, sizeof current_tcmh); 3869 memcpy(&current_tcmh, &shdr.mh, sizeof current_tcmh);
@@ -3886,13 +3888,13 @@ static bool tagcache_dumpsave(void)
3886 3888
3887 /* Create the header */ 3889 /* Create the header */
3888 shdr.magic = TAGCACHE_STATEFILE_MAGIC; 3890 shdr.magic = TAGCACHE_STATEFILE_MAGIC;
3889 shdr.hdr = hdr; 3891 shdr.hdr = ramcache_hdr;
3890 memcpy(&shdr.mh, &current_tcmh, sizeof current_tcmh); 3892 memcpy(&shdr.mh, &current_tcmh, sizeof current_tcmh);
3891 memcpy(&shdr.tc_stat, &tc_stat, sizeof tc_stat); 3893 memcpy(&shdr.tc_stat, &tc_stat, sizeof tc_stat);
3892 write(fd, &shdr, sizeof shdr); 3894 write(fd, &shdr, sizeof shdr);
3893 3895
3894 /* And dump the data too */ 3896 /* And dump the data too */
3895 write(fd, hdr, tc_stat.ramcache_allocated); 3897 write(fd, ramcache_hdr, tc_stat.ramcache_allocated);
3896 close(fd); 3898 close(fd);
3897 3899
3898 return true; 3900 return true;
@@ -3936,7 +3938,7 @@ static bool load_tagcache(void)
3936 /* Master header copy should already match, this can be redundant to do. */ 3938 /* Master header copy should already match, this can be redundant to do. */
3937 memcpy(&current_tcmh, &tcmh, sizeof current_tcmh); 3939 memcpy(&current_tcmh, &tcmh, sizeof current_tcmh);
3938 3940
3939 idx = hdr->indices; 3941 idx = ramcache_hdr->indices;
3940 3942
3941 /* Load the master index table. */ 3943 /* Load the master index table. */
3942 for (i = 0; i < tcmh.tch.entry_count; i++) 3944 for (i = 0; i < tcmh.tch.entry_count; i++)
@@ -3952,7 +3954,8 @@ static bool load_tagcache(void)
3952 } 3954 }
3953 3955
3954 bytesleft -= sizeof(struct index_entry); 3956 bytesleft -= sizeof(struct index_entry);
3955 if (bytesleft < 0 || ((long)idx - (long)hdr->indices) >= tc_stat.ramcache_allocated) 3957 if (bytesleft < 0 ||
3958 ((long)idx - (long)ramcache_hdr->indices) >= tc_stat.ramcache_allocated)
3956 { 3959 {
3957 logf("too big tagcache."); 3960 logf("too big tagcache.");
3958 close(fd); 3961 close(fd);
@@ -3976,7 +3979,7 @@ static bool load_tagcache(void)
3976 3979
3977 //p = ((void *)p+1); 3980 //p = ((void *)p+1);
3978 p = (char *)((long)p & ~0x03) + 0x04; 3981 p = (char *)((long)p & ~0x03) + 0x04;
3979 hdr->tags[tag] = p; 3982 ramcache_hdr->tags[tag] = p;
3980 3983
3981 /* Check the header. */ 3984 /* Check the header. */
3982 tch = (struct tagcache_header *)p; 3985 tch = (struct tagcache_header *)p;
@@ -3985,9 +3988,9 @@ static bool load_tagcache(void)
3985 if ( (fd = open_tag_fd(tch, tag, false)) < 0) 3988 if ( (fd = open_tag_fd(tch, tag, false)) < 0)
3986 return false; 3989 return false;
3987 3990
3988 for (hdr->entry_count[tag] = 0; 3991 for (ramcache_hdr->entry_count[tag] = 0;
3989 hdr->entry_count[tag] < tch->entry_count; 3992 ramcache_hdr->entry_count[tag] < tch->entry_count;
3990 hdr->entry_count[tag]++) 3993 ramcache_hdr->entry_count[tag]++)
3991 { 3994 {
3992 long pos; 3995 long pos;
3993 3996
@@ -4016,7 +4019,7 @@ static bool load_tagcache(void)
4016 int dc; 4019 int dc;
4017# endif 4020# endif
4018 4021
4019 idx = &hdr->indices[fe->idx_id]; 4022 idx = &ramcache_hdr->indices[fe->idx_id];
4020 4023
4021 if (fe->tag_length >= (long)sizeof(buf)-1) 4024 if (fe->tag_length >= (long)sizeof(buf)-1)
4022 { 4025 {
@@ -4477,7 +4480,7 @@ void tagcache_build(const char *path)
4477#endif 4480#endif
4478 4481
4479#ifdef HAVE_TC_RAMCACHE 4482#ifdef HAVE_TC_RAMCACHE
4480 if (hdr) 4483 if (ramcache_hdr)
4481 { 4484 {
4482 /* Import runtime statistics if we just initialized the db. */ 4485 /* Import runtime statistics if we just initialized the db. */
4483 if (current_tcmh.serial == 0) 4486 if (current_tcmh.serial == 0)
@@ -4491,7 +4494,7 @@ void tagcache_build(const char *path)
4491#ifdef HAVE_TC_RAMCACHE 4494#ifdef HAVE_TC_RAMCACHE
4492static void load_ramcache(void) 4495static void load_ramcache(void)
4493{ 4496{
4494 if (!hdr) 4497 if (!ramcache_hdr)
4495 return ; 4498 return ;
4496 4499
4497 cpu_boost(true); 4500 cpu_boost(true);
@@ -4504,7 +4507,7 @@ static void load_ramcache(void)
4504 /* If loading failed, it must indicate some problem with the db 4507 /* If loading failed, it must indicate some problem with the db
4505 * so disable it entirely to prevent further issues. */ 4508 * so disable it entirely to prevent further issues. */
4506 tc_stat.ready = false; 4509 tc_stat.ready = false;
4507 hdr = NULL; 4510 ramcache_hdr = NULL;
4508 } 4511 }
4509 4512
4510 cpu_boost(false); 4513 cpu_boost(false);
@@ -4667,7 +4670,7 @@ static int get_progress(void)
4667#endif 4670#endif
4668#ifdef HAVE_TC_RAMCACHE 4671#ifdef HAVE_TC_RAMCACHE
4669 { 4672 {
4670 if (hdr && tc_stat.ramcache) 4673 if (ramcache_hdr && tc_stat.ramcache)
4671 total_count = current_tcmh.tch.entry_count; 4674 total_count = current_tcmh.tch.entry_count;
4672 } 4675 }
4673#endif 4676#endif