Commit cc88a234 authored by Ell's avatar Ell

buffer: avoid over-trimming cache if already trimmed

In gegl_tile_handler_cache_trim(), check if the cache needs
trimming before deciding how much to over-trim, and bail if no
trimming is needed in the first place.  This is necessary, since
two threads may try to trim the cache concurrently, in which case
one thread will block until the other thread finishes trimming.  At
this point, we want the other thread to avoid trimming, instead of
increasing the over-trim ratio, and trimming extra tiles.
parent 4d4cf2fd
......@@ -529,6 +529,15 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
g_mutex_lock (&mutex);
target_size = gegl_buffer_config ()->tile_cache_size;
if ((guintptr) g_atomic_pointer_get (&cache_total) <= target_size)
{
g_mutex_unlock (&mutex);
return TRUE;
}
time = g_get_monotonic_time ();
if (time - last_time < GEGL_CACHE_TRIM_INTERVAL)
......@@ -541,7 +550,6 @@ gegl_tile_handler_cache_trim (GeglTileHandlerCache *cache)
ratio = GEGL_CACHE_TRIM_RATIO_MIN;
}
target_size = gegl_buffer_config ()->tile_cache_size;
target_size -= target_size * ratio;
while ((guintptr) g_atomic_pointer_get (&cache_total) > target_size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment