diff options
author | Vicent Marti <tanoku@gmail.com> | 2013-04-03 20:57:30 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2013-04-22 16:50:50 +0200 |
commit | c4e91d4500bdd357fbf7378bc10648a482513fa6 (patch) | |
tree | c0be7df93bd56f52c20835359c3a89e11562c7c2 /src/cache.c | |
parent | 6b90e244de78640b751d0923c91c3868e12b8658 (diff) | |
download | libgit2-c4e91d4500bdd357fbf7378bc10648a482513fa6.tar.gz |
Random eviction
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cache.c b/src/cache.c index a0925a188..f49515ef3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -32,7 +32,6 @@ size_t git_cache__max_object_size = 4096; int git_cache_init(git_cache *cache) { - cache->lru_count = 0; cache->map = git_oidmap_alloc(); git_mutex_init(&cache->lock); return 0; @@ -44,6 +43,24 @@ void git_cache_free(git_cache *cache) git_mutex_free(&cache->lock); } +static void cache_evict_entries(git_cache *cache, size_t evict) +{ + uint32_t seed = rand(); + + /* do not infinite loop if there's not enough entries to evict */ + if (evict > kh_size(cache->map)) + return; + + while (evict > 0) { + khiter_t pos = seed++ % kh_end(cache->map); + + if (kh_exist(cache->map, pos)) { + kh_del(oid, cache->map, pos); + evict--; + } + } +} + static bool cache_should_store(git_otype object_type, size_t object_size) { if (!git_cache__store_types[object_type]) |