Skip to content

Commit

Permalink
Merge pull request #291 from qwe661234/master
Browse files Browse the repository at this point in the history
Fix cache_free fucntion
  • Loading branch information
jserv authored Dec 14, 2023
2 parents ec914f4 + 1eeafe4 commit 03bd04c
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 03bd04c

Please sign in to comment.