[gnome-builder] task-cache: add evict_all() helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] task-cache: add evict_all() helper
- Date: Mon, 5 Dec 2016 00:03:06 +0000 (UTC)
commit 2be02bf0b399a94c02cf1c1d18dc5687a708d1e0
Author: Christian Hergert <chergert redhat com>
Date: Sun Dec 4 15:34:40 2016 -0800
task-cache: add evict_all() helper
This is a simple evict all implementation. We could probably do a better
implementation, but this will work for now.
contrib/egg/egg-task-cache.c | 25 +++++++++++++++++++++++++
contrib/egg/egg-task-cache.h | 1 +
2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/contrib/egg/egg-task-cache.c b/contrib/egg/egg-task-cache.c
index c932a53..3d466eb 100644
--- a/contrib/egg/egg-task-cache.c
+++ b/contrib/egg/egg-task-cache.c
@@ -267,6 +267,31 @@ egg_task_cache_evict (EggTaskCache *self,
return egg_task_cache_evict_full (self, key, TRUE);
}
+void
+egg_task_cache_evict_all (EggTaskCache *self)
+{
+ guint size;
+
+ g_return_if_fail (EGG_IS_TASK_CACHE (self));
+
+ size = g_hash_table_size (self->cache);
+
+ while (self->evict_heap->len > 0)
+ {
+ CacheItem *item;
+
+ /* The cache item is owned by the hashtable, so safe to "leak" here */
+ egg_heap_extract_index (self->evict_heap, self->evict_heap->len - 1, &item);
+ }
+
+ g_hash_table_remove_all (self->cache);
+
+ EGG_COUNTER_SUB (cached, size);
+
+ if (self->evict_source != NULL)
+ evict_source_rearm (self->evict_source);
+}
+
/**
* egg_task_cache_peek:
* @self: An #EggTaskCache
diff --git a/contrib/egg/egg-task-cache.h b/contrib/egg/egg-task-cache.h
index fcf5e47..1935ed4 100644
--- a/contrib/egg/egg-task-cache.h
+++ b/contrib/egg/egg-task-cache.h
@@ -72,6 +72,7 @@ gpointer egg_task_cache_get_finish (EggTaskCache *self,
GError **error);
gboolean egg_task_cache_evict (EggTaskCache *self,
gconstpointer key);
+void egg_task_cache_evict_all (EggTaskCache *self);
gpointer egg_task_cache_peek (EggTaskCache *self,
gconstpointer key);
GPtrArray *egg_task_cache_get_values (EggTaskCache *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]