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-06 00:38:14 +0400
committerVicent Marti <tanoku@gmail.com>2013-04-22 18:50:51 +0400
commite183e375b83044d7852b8253553c4f782d73c140 (patch)
treea51829701f67ef521d3695bde2a74d0f132d7e1f /src/cache.c
parente16e268457ab4ab8a4edc8153deca2c8c22dc757 (diff)
Clear the cache when there are too many items to expire
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/cache.c b/src/cache.c
index f3ab8a684..9f3290f01 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -63,14 +63,33 @@ void git_cache_free(git_cache *cache)
git_mutex_free(&cache->lock);
}
+void git_cache_clear(git_cache *cache)
+{
+ git_cached_obj *evict = NULL;
+
+ if (git_mutex_lock(&cache->lock) < 0)
+ return;
+
+ kh_foreach_value(cache->map, evict, {
+ git_cached_obj_decref(evict);
+ });
+
+ kh_clear(oid, cache->map);
+ cache->used_memory = 0;
+
+ git_mutex_unlock(&cache->lock);
+}
+
/* Call with lock, yo */
static void cache_evict_entries(git_cache *cache, size_t evict_count)
{
uint32_t seed = rand();
/* do not infinite loop if there's not enough entries to evict */
- if (evict_count > kh_size(cache->map))
+ if (evict_count > kh_size(cache->map)) {
+ git_cache_clear(cache);
return;
+ }
while (evict_count > 0) {
khiter_t pos = seed++ % kh_end(cache->map);