buffer: make more calls conditional of number of threads being > 1

parent 327080a4
......@@ -113,6 +113,7 @@ gegl_buffer_get_pixel (GeglBuffer *buffer,
}
}
g_rec_mutex_lock (&buffer->tile_storage->mutex);
{
gint tile_width = buffer->tile_width;
gint tile_height = buffer->tile_height;
......@@ -159,6 +160,7 @@ gegl_buffer_get_pixel (GeglBuffer *buffer,
}
}
}
g_rec_mutex_unlock (&buffer->tile_storage->mutex);
}
static inline void
......@@ -177,6 +179,7 @@ __gegl_buffer_set_pixel (GeglBuffer *buffer,
x >= abyss->x + abyss->width)
return;
g_rec_mutex_lock (&buffer->tile_storage->mutex);
{
gint tile_width = buffer->tile_width;
gint tile_height = buffer->tile_height;
......@@ -229,6 +232,7 @@ __gegl_buffer_set_pixel (GeglBuffer *buffer,
gegl_tile_unlock (tile);
}
}
g_rec_mutex_unlock (&buffer->tile_storage->mutex);
}
enum _GeglBufferSetFlag {
......
......@@ -1110,14 +1110,18 @@ gegl_buffer_try_lock (GeglBuffer *buffer)
{
GeglTileBackend *backend = gegl_buffer_backend (buffer);
g_mutex_lock (&buffer->tile_storage->mutex);
gboolean threaded = gegl_config_threads ()>1;
if (threaded)
g_mutex_lock (&buffer->tile_storage->mutex);
if (buffer->lock_count > 0)
buffer->lock_count++;
else if (gegl_tile_backend_file_try_lock (GEGL_TILE_BACKEND_FILE (backend)))
buffer->lock_count++;
else
ret = FALSE;
g_mutex_unlock (&buffer->tile_storage->mutex);
if (threaded)
g_mutex_unlock (&buffer->tile_storage->mutex);
}
return ret;
......@@ -1142,9 +1146,11 @@ gegl_buffer_unlock (GeglBuffer *buffer)
if (gegl_buffer_is_shared (buffer))
{
gboolean threaded = gegl_config_threads ()>1;
GeglTileBackend *backend = gegl_buffer_backend (buffer);
g_mutex_lock (&buffer->tile_storage->mutex);
if (threaded)
g_mutex_lock (&buffer->tile_storage->mutex);
buffer->lock_count--;
g_assert (buffer->lock_count >= 0);
......@@ -1152,7 +1158,8 @@ gegl_buffer_unlock (GeglBuffer *buffer)
if (buffer->lock_count == 0)
ret = gegl_tile_backend_file_unlock (GEGL_TILE_BACKEND_FILE (backend));
g_mutex_unlock (&buffer->tile_storage->mutex);
if (threaded)
g_mutex_unlock (&buffer->tile_storage->mutex);
}
return ret;
......
......@@ -37,6 +37,8 @@
#include "gegl-sampler-nohalo.h"
#include "gegl-sampler-lohalo.h"
#include "gegl-config.h"
enum
{
PROP_0,
......@@ -524,6 +526,8 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
}*/
static GMutex mutex = {0,};
gboolean threaded = gegl_config_threads ()>1;
if (!format)
format = buffer->soft_format;
......@@ -534,7 +538,8 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
gegl_buffer_cl_cache_flush (buffer, &rect);
}
g_mutex_lock (&mutex);
if (threaded)
g_mutex_lock (&mutex);
/* unset the cached sampler if it dosn't match the needs */
if (buffer->sampler != NULL &&
......@@ -562,7 +567,8 @@ gegl_buffer_sample_at_level (GeglBuffer *buffer,
}
buffer->sampler->get(buffer->sampler, x, y, scale, dest, repeat_mode);
g_mutex_unlock (&mutex);
if (threaded)
g_mutex_unlock (&mutex);
}
......
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