Added a mutex for clutter asynchronous textures threads.

Bug #1453 - Asynchronous texture loading can starve cpu.

Add a mutex that is held in the loader threads during the image
decoding. We were spawning and starting a thread for each asynchronously
loaded texture. This can cause cpu / memory starvation when many pixbuf
loaders allocate their temporary memory at the same time.

Also added -fno-strict-aliasing to MAINTAINER_CFLAGS in configure.ac
to avoid incorrect warnings caused by the static mutex code.
This commit is contained in:
Øyvind Kolås 2009-02-17 12:00:08 +00:00
parent 2fe0228f92
commit 57ffcdf014
2 changed files with 18 additions and 2 deletions

View File

@ -104,6 +104,7 @@ struct _ClutterTexturePrivate
gchar *load_filename;
CoglBitmap *load_bitmap;
GError *load_error;
gboolean abort;
};
enum
@ -639,6 +640,7 @@ clutter_texture_async_load_cancel (ClutterTexture *texture)
if (priv->load_thread)
{
priv->abort = TRUE;
g_thread_join (priv->load_thread);
priv->load_thread = NULL;
}
@ -1609,12 +1611,25 @@ clutter_texture_thread_cb (gpointer data)
static gpointer
clutter_texture_thread_func (gpointer data)
{
ClutterTexture *self = data;
static GStaticMutex thread_load_mutex = G_STATIC_MUTEX_INIT;
ClutterTexture *self = data;
ClutterTexturePrivate *priv = self->priv;
/* we aquire the shared lock, only one thread is allowed to
* be loading at a time
*/
g_static_mutex_lock (&thread_load_mutex);
if (priv->abort)
{
g_static_mutex_unlock (&thread_load_mutex);
g_free (priv->load_filename);
priv->load_filename = NULL;
return NULL;
}
/* Try loading with imaging backend */
priv->load_bitmap = cogl_bitmap_new_from_file (priv->load_filename,
&priv->load_error);
g_static_mutex_unlock (&thread_load_mutex);
g_free (priv->load_filename);
priv->load_filename = NULL;
@ -1649,6 +1664,7 @@ clutter_texture_idle_func (gpointer data)
return FALSE;
}
/*
* clutter_texture_async_load:
* @self: a #ClutterTexture

View File

@ -590,7 +590,7 @@ AC_ARG_ENABLE([maintainer-flags],
enable_maintainer_flags=maintainer_flags_default)
if test "x$enable_maintainer_flags" = "xyes"; then
MAINTAINER_CFLAGS="-Werror -Wall -Wshadow -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self"
MAINTAINER_CFLAGS="-Werror -Wall -Wshadow -Wcast-align -Wno-strict-aliasing -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self"
fi
AC_SUBST(MAINTAINER_CFLAGS)