Skip to content

Commit

Permalink
Fix cache_free fucntion
Browse files Browse the repository at this point in the history
After we introduced the memory pool for blocks and IRs, we don't need
to free the memory of blocks and IRs by cache.
  • Loading branch information
qwe661234 committed Dec 14, 2023
1 parent 90b42a6 commit 1eeafe4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
25 changes: 5 additions & 20 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,31 +515,16 @@ void *cache_put(cache_t *cache, uint32_t key, void *value)
return delete_value;
}

void cache_free(cache_t *cache, void (*callback)(void *))
void cache_free(cache_t *cache)
{
#if RV32_HAS(ARC)
for (int i = 0; i < N_CACHE_LIST_TYPES; i++) {
arc_entry_t *entry, *safe;
#ifdef __HAVE_TYPEOF
list_for_each_entry_safe (entry, safe, cache->lists[i], list)
#else
list_for_each_entry_safe (entry, safe, cache->lists[i], list,
arc_entry_t)
#endif
#else /* !RV32_HAS(ARC) */
for (int i = 0; i < THRESHOLD; i++) {
if (list_empty(cache->lists[i]))
continue;
lfu_entry_t *entry, *safe;
#ifdef __HAVE_TYPEOF
list_for_each_entry_safe (entry, safe, cache->lists[i], list)
free(cache->lists[i]);
}
#else
list_for_each_entry_safe (entry, safe, cache->lists[i], list,
lfu_entry_t)
for (int i = 0; i < THRESHOLD; i++)
free(cache->lists[i]);
#endif
#endif
callback(entry->value);
}
mpool_destroy(cache_mp);
free(cache->map->ht_list_head);
free(cache->map);
Expand Down
2 changes: 1 addition & 1 deletion src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ void *cache_put(struct cache *cache, uint32_t key, void *value);
* @cache: a pointer points to target cache
* @callback: a function for freeing cache entry completely
*/
void cache_free(struct cache *cache, void (*callback)(void *));
void cache_free(struct cache *cache);
2 changes: 1 addition & 1 deletion tests/cache/test-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char *argv[])
assert(cache);
printf("NEW CACHE\n");
} else if (!strcmp(arr[0], "FREE\n")) {
cache_free(cache, free);
cache_free(cache);
printf("FREE CACHE\n");
}
}
Expand Down

0 comments on commit 1eeafe4

Please sign in to comment.