summaryrefslogtreecommitdiff
path: root/src/cairo-cache.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2005-06-25 23:24:19 +0000
committerKeith Packard <keithp@keithp.com>2005-06-25 23:24:19 +0000
commit3b0c3d0ee84f991347df12249f944c780dde99f8 (patch)
tree08a88cdad152506f1bd1b91145de533ae467d4cb /src/cairo-cache.c
parent574f7f560bf2cc851ad4f3267840e37fa06611fa (diff)
Provide locking macros, implement with pthreads.
Add _cairo_cache_shrink_to which reduces cache memory usage to a specified level. Change global glyph and xlib glyphset caches behaviour to only shrink cache on unlock. This is done by telling the cache code to never shrink (max_memory == 0), and then manually shrinking using _cairo_cache_shrink_to from the unlock function. Fix Carl's variable renaming mixing (cache = cache). reviewed by: cworth
Diffstat (limited to 'src/cairo-cache.c')
-rw-r--r--src/cairo-cache.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index e7547bc2..a0c20222 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -383,6 +383,19 @@ _cairo_cache_destroy (cairo_cache_t *cache)
cache->backend->destroy_cache (cache);
}
+void
+_cairo_cache_shrink_to (cairo_cache_t *cache,
+ unsigned long max_memory)
+{
+ unsigned long idx;
+ /* Make some entries die if we're under memory pressure. */
+ while (cache->live_entries > 0 && cache->used_memory > max_memory) {
+ idx = _random_entry (cache, NULL) - cache->entries;
+ assert (idx < cache->arrangement->size);
+ _entry_destroy (cache, idx);
+ }
+}
+
cairo_status_t
_cairo_cache_lookup (cairo_cache_t *cache,
void *key,
@@ -390,7 +403,6 @@ _cairo_cache_lookup (cairo_cache_t *cache,
int *created_entry)
{
- unsigned long idx;
cairo_status_t status = CAIRO_STATUS_SUCCESS;
cairo_cache_entry_base_t **slot = NULL, *new_entry;
@@ -440,14 +452,8 @@ _cairo_cache_lookup (cairo_cache_t *cache,
/* Store the hash value in case the backend forgot. */
new_entry->hashcode = cache->backend->hash (cache, key);
- /* Make some entries die if we're under memory pressure. */
- while (cache->live_entries > 0 &&
- cache->max_memory > 0 &&
- ((cache->max_memory - cache->used_memory) < new_entry->memory)) {
- idx = _random_entry (cache, NULL) - cache->entries;
- assert (idx < cache->arrangement->size);
- _entry_destroy (cache, idx);
- }
+ if (cache->live_entries && cache->max_memory)
+ _cairo_cache_shrink_to (cache, cache->max_memory);
/* Can't assert this; new_entry->memory may be larger than max_memory */
/* assert(cache->max_memory >= (cache->used_memory + new_entry->memory)); */