Lines Matching refs:cache

375     cache_t* cache = (cache_t*)calloc(1, sizeof(cache_t));
376 return cache;
381 static void* _cache_malloc(cache_t* cache, size_t len)
392 CACHE_NOISY(ALOGI("Allocated large cache mem block: %p size %d", res, len));
394 if (cache->memBlocks == NULL) {
396 cache->memBlocks = res;
398 *(void**)res = *(void**)cache->memBlocks;
399 *(void**)cache->memBlocks = res;
403 int8_t* res = cache->curMemBlockAvail;
405 if (cache->memBlocks == NULL || nextPos > cache->curMemBlockEnd) {
410 CACHE_NOISY(ALOGI("Allocated new cache mem block: %p", newBlock));
411 *(void**)newBlock = cache->memBlocks;
412 cache->memBlocks = newBlock;
413 res = cache->curMemBlockAvail = newBlock + sizeof(void*);
414 cache->curMemBlockEnd = newBlock + CACHE_BLOCK_SIZE;
418 res, len, cache->memBlocks, nextPos));
419 cache->curMemBlockAvail = nextPos;
423 static void* _cache_realloc(cache_t* cache, void* cur, size_t origLen, size_t len)
426 void* alloc = _cache_malloc(cache, len);
433 static void _inc_num_cache_collected(cache_t* cache)
435 cache->numCollected++;
436 if ((cache->numCollected%20000) == 0) {
437 ALOGI("Collected cache so far: %d directories, %d files",
438 cache->numDirs, cache->numFiles);
442 static cache_dir_t* _add_cache_dir_t(cache_t* cache, cache_dir_t* parent, const char *name)
445 cache_dir_t* dir = (cache_dir_t*)_cache_malloc(cache, sizeof(cache_dir_t)+nameLen+1);
452 if (cache->numDirs >= cache->availDirs) {
453 size_t newAvail = cache->availDirs < 1000 ? 1000 : cache->availDirs*2;
454 cache_dir_t** newDirs = (cache_dir_t**)_cache_realloc(cache, cache->dirs,
455 cache->availDirs*sizeof(cache_dir_t*), newAvail*sizeof(cache_dir_t*));
457 ALOGE("Failure growing cache dirs array for %s\n", name);
460 cache->availDirs = newAvail;
461 cache->dirs = newDirs;
463 cache->dirs[cache->numDirs] = dir;
464 cache->numDirs++;
468 _inc_num_cache_collected(cache);
475 static cache_file_t* _add_cache_file_t(cache_t* cache, cache_dir_t* dir, time_t modTime,
479 cache_file_t* file = (cache_file_t*)_cache_malloc(cache, sizeof(cache_file_t)+nameLen+1);
484 if (cache->numFiles >= cache->availFiles) {
485 size_t newAvail = cache->availFiles < 1000 ? 1000 : cache->availFiles*2;
486 cache_file_t** newFiles = (cache_file_t**)_cache_realloc(cache, cache->files,
487 cache->availFiles*sizeof(cache_file_t*), newAvail*sizeof(cache_file_t*));
489 ALOGE("Failure growing cache file array for %s\n", name);
492 cache->availFiles = newAvail;
493 cache->files = newFiles;
496 cache->numFiles, cache->files));
497 cache->files[cache->numFiles] = file;
498 cache->numFiles++;
500 _inc_num_cache_collected(cache);
507 static int _add_cache_files(cache_t *cache, cache_dir_t *parentDir, const char *dirName,
523 cacheDir = _add_cache_dir_t(cache, parentDir, dirName);
550 cacheDir = _add_cache_dir_t(cache, parentDir, dirName);
559 _add_cache_files(cache, cacheDir, name, subdir, pathBase,
579 cacheDir = _add_cache_dir_t(cache, parentDir, dirName);
594 _add_cache_file_t(cache, cacheDir, s.st_mtime, name);
596 ALOGW("Unable to stat cache file %s; deleting\n", pathBase);
620 void add_cache_files(cache_t* cache, const char *basepath, const char *cachedir)
657 CACHE_NOISY(ALOGI("Adding cache files from dir: %s\n", dirname));
661 _add_cache_files(cache, NULL, dirname, subdir, dirname, dirname+dirnameLen,
678 // since when we were constructing the cache entries our maximum
726 void clear_cache_files(cache_t* cache, int64_t free_size)
732 ALOGI("Collected cache files: %d directories, %d files",
733 cache->numDirs, cache->numFiles);
736 qsort(cache->files, cache->numFiles, sizeof(cache_file_t*),
740 for (i=cache->numDirs; i>0; i--) {
741 cache_dir_t* dir = cache->dirs[i-1];
748 for (i=0; i<cache->numFiles; i++) {
756 cache_file_t* file = cache->files[i];
769 void finish_cache_collection(cache_t* cache)
773 CACHE_NOISY(ALOGI("clear_cache_files: %d dirs, %d files\n", cache->numDirs, cache->numFiles));
775 for (i=0; i<cache->numDirs; i++) {
776 cache_dir_t* dir = cache->dirs[i];
780 for (i=0; i<cache->numFiles; i++) {
781 cache_file_t* file = cache->files[i];
785 void* block = cache->memBlocks;
788 CACHE_NOISY(ALOGI("Freeing cache mem block: %p", block));
792 free(cache);