Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2013-04-03 22:57:30 +0400
committerVicent Marti <tanoku@gmail.com>2013-04-22 18:50:50 +0400
commitc4e91d4500bdd357fbf7378bc10648a482513fa6 (patch)
treec0be7df93bd56f52c20835359c3a89e11562c7c2 /src/cache.c
parent6b90e244de78640b751d0923c91c3868e12b8658 (diff)
Random eviction
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c19
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])