Lines Matching refs:cache

488     cache_t* cache = (cache_t*)calloc(1, sizeof(cache_t));
489 return cache;
494 static void* _cache_malloc(cache_t* cache, size_t len)
505 CACHE_NOISY(ALOGI("Allocated large cache mem block: %p size %d", res, len));
507 if (cache->memBlocks == NULL) {
509 cache->memBlocks = res;
511 *(void**)res = *(void**)cache->memBlocks;
512 *(void**)cache->memBlocks = res;
516 int8_t* res = cache->curMemBlockAvail;
518 if (cache->memBlocks == NULL || nextPos > cache->curMemBlockEnd) {
523 CACHE_NOISY(ALOGI("Allocated new cache mem block: %p", newBlock));
524 *(void**)newBlock = cache->memBlocks;
525 cache->memBlocks = newBlock;
526 res = cache->curMemBlockAvail = newBlock + sizeof(void*);
527 cache->curMemBlockEnd = newBlock + CACHE_BLOCK_SIZE;
531 res, len, cache->memBlocks, nextPos));
532 cache->curMemBlockAvail = nextPos;
536 static void* _cache_realloc(cache_t* cache, void* cur, size_t origLen, size_t len)
539 void* alloc = _cache_malloc(cache, len);
546 static void _inc_num_cache_collected(cache_t* cache)
548 cache->numCollected++;
549 if ((cache->numCollected%20000) == 0) {
550 ALOGI("Collected cache so far: %zd directories, %zd files",
551 cache->numDirs, cache->numFiles);
555 static cache_dir_t* _add_cache_dir_t(cache_t* cache, cache_dir_t* parent, const char *name)
558 cache_dir_t* dir = (cache_dir_t*)_cache_malloc(cache, sizeof(cache_dir_t)+nameLen+1);
565 if (cache->numDirs >= cache->availDirs) {
566 size_t newAvail = cache->availDirs < 1000 ? 1000 : cache->availDirs*2;
567 cache_dir_t** newDirs = (cache_dir_t**)_cache_realloc(cache, cache->dirs,
568 cache->availDirs*sizeof(cache_dir_t*), newAvail*sizeof(cache_dir_t*));
570 ALOGE("Failure growing cache dirs array for %s\n", name);
573 cache->availDirs = newAvail;
574 cache->dirs = newDirs;
576 cache->dirs[cache->numDirs] = dir;
577 cache->numDirs++;
581 _inc_num_cache_collected(cache);
588 static cache_file_t* _add_cache_file_t(cache_t* cache, cache_dir_t* dir, time_t modTime,
592 cache_file_t* file = (cache_file_t*)_cache_malloc(cache, sizeof(cache_file_t)+nameLen+1);
597 if (cache->numFiles >= cache->availFiles) {
598 size_t newAvail = cache->availFiles < 1000 ? 1000 : cache->availFiles*2;
599 cache_file_t** newFiles = (cache_file_t**)_cache_realloc(cache, cache->files,
600 cache->availFiles*sizeof(cache_file_t*), newAvail*sizeof(cache_file_t*));
602 ALOGE("Failure growing cache file array for %s\n", name);
605 cache->availFiles = newAvail;
606 cache->files = newFiles;
609 cache->numFiles, cache->files));
610 cache->files[cache->numFiles] = file;
611 cache->numFiles++;
613 _inc_num_cache_collected(cache);
620 static int _add_cache_files(cache_t *cache, cache_dir_t *parentDir, const char *dirName,
636 cacheDir = _add_cache_dir_t(cache, parentDir, dirName);
663 cacheDir = _add_cache_dir_t(cache, parentDir, dirName);
672 _add_cache_files(cache, cacheDir, name, subdir, pathBase,
692 cacheDir = _add_cache_dir_t(cache, parentDir, dirName);
707 _add_cache_file_t(cache, cacheDir, s.st_mtime, name);
709 ALOGW("Unable to stat cache file %s; deleting\n", pathBase);
733 void add_cache_files(cache_t* cache, const char *basepath, const char *cachedir)
770 CACHE_NOISY(ALOGI("Adding cache files from dir: %s\n", dirname));
774 _add_cache_files(cache, NULL, dirname, subdir, dirname, dirname+dirnameLen,
791 // since when we were constructing the cache entries our maximum
839 void clear_cache_files(cache_t* cache, int64_t free_size)
845 ALOGI("Collected cache files: %zd directories, %zd files",
846 cache->numDirs, cache->numFiles);
849 qsort(cache->files, cache->numFiles, sizeof(cache_file_t*),
853 for (i=cache->numDirs; i>0; i--) {
854 cache_dir_t* dir = cache->dirs[i-1];
861 for (i=0; i<cache->numFiles; i++) {
869 cache_file_t* file = cache->files[i];
882 void finish_cache_collection(cache_t* cache)
886 CACHE_NOISY(ALOGI("clear_cache_files: %d dirs, %d files\n", cache->numDirs, cache->numFiles));
888 for (i=0; i<cache->numDirs; i++) {
889 cache_dir_t* dir = cache->dirs[i];
893 for (i=0; i<cache->numFiles; i++) {
894 cache_file_t* file = cache->files[i];
898 void* block = cache->memBlocks;
901 CACHE_NOISY(ALOGI("Freeing cache mem block: %p", block));
905 free(cache);