[gdk-pixbuf] Remove locking around thread-unsafe modules



commit 6068c41010b3089341dd297182ec0656702d67af
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 3 08:07:37 2013 -0500

    Remove locking around thread-unsafe modules
    
    It did not work, and was causing deadlocks. With pango becoming
    thread-safe this cycle, the last relevant non-threadsafe loader,
    svg, will be fixed.
    https://bugzilla.gnome.org/show_bug.cgi?id=473862

 gdk-pixbuf/gdk-pixbuf-animation.c |    9 +-----
 gdk-pixbuf/gdk-pixbuf-io.c        |   48 +------------------------------------
 gdk-pixbuf/gdk-pixbuf-loader.c    |   12 ---------
 gdk-pixbuf/gdk-pixbuf-private.h   |    3 --
 4 files changed, 3 insertions(+), 69 deletions(-)
---
diff --git a/gdk-pixbuf/gdk-pixbuf-animation.c b/gdk-pixbuf/gdk-pixbuf-animation.c
index 3ad8141..abd0a4d 100644
--- a/gdk-pixbuf/gdk-pixbuf-animation.c
+++ b/gdk-pixbuf/gdk-pixbuf-animation.c
@@ -132,7 +132,6 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
 	guchar buffer [1024];
 	GdkPixbufModule *image_module;
         gchar *display_name;
-        gboolean locked = FALSE;
 
 	g_return_val_if_fail (filename != NULL, NULL);
         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -206,15 +205,13 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
 		if (pixbuf == NULL) {
                         g_free (display_name);
                         animation = NULL;
-                        goto out_unlock;
+                        goto out;
                 }
 
                 animation = gdk_pixbuf_non_anim_new (pixbuf);
 
                 g_object_unref (pixbuf);
 	} else {
-                locked = _gdk_pixbuf_lock (image_module);
-
 		fseek (f, 0, SEEK_SET);
 		animation = (* image_module->load_animation) (f, error);
 
@@ -241,9 +238,7 @@ gdk_pixbuf_animation_new_from_file (const char *filename,
 
         g_free (display_name);
 
- out_unlock:
-        if (locked)
-                _gdk_pixbuf_unlock (image_module);
+ out:
 	return animation;
 }
 
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index 59bc1ee..0714afd 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -190,28 +190,6 @@ format_check (GdkPixbufModule *module, guchar *buffer, int size)
 }
 
 G_LOCK_DEFINE_STATIC (init_lock);
-G_LOCK_DEFINE_STATIC (threadunsafe_loader_lock);
-
-gboolean
-_gdk_pixbuf_lock (GdkPixbufModule *image_module)
-{
-        if (g_threads_got_initialized &&
-            !(image_module->info->flags & GDK_PIXBUF_FORMAT_THREADSAFE)) {
-                G_LOCK (threadunsafe_loader_lock);
-
-                return TRUE;
-        }
-
-        return FALSE;
-}
- 
-void
-_gdk_pixbuf_unlock (GdkPixbufModule *image_module)
-{
-        if (!(image_module->info->flags & GDK_PIXBUF_FORMAT_THREADSAFE)) {
-                G_UNLOCK (threadunsafe_loader_lock);
-        }
-}
 
 static GSList *file_formats = NULL;
 
@@ -1005,9 +983,6 @@ _gdk_pixbuf_generic_image_load (GdkPixbufModule *module,
         GdkPixbuf *pixbuf = NULL;
         GdkPixbufAnimation *animation = NULL;
         gpointer context;
-        gboolean locked;
-
-        locked = _gdk_pixbuf_lock (module);
 
         if (module->load != NULL) {
                 pixbuf = (* module->load) (f, error);
@@ -1048,8 +1023,6 @@ _gdk_pixbuf_generic_image_load (GdkPixbufModule *module,
         }
 
  out:
-        if (locked)
-                _gdk_pixbuf_unlock (module);
         return pixbuf;
 }
 
@@ -1951,7 +1924,6 @@ gdk_pixbuf_new_from_xpm_data (const char **data)
         GdkPixbuf *pixbuf;
         GError *error = NULL;
         GdkPixbufModule *xpm_module;
-        gboolean locked;
 
         g_return_val_if_fail (data != NULL, NULL);
 
@@ -1968,8 +1940,6 @@ gdk_pixbuf_new_from_xpm_data (const char **data)
                 return NULL;
         }
 
-        locked = _gdk_pixbuf_lock (xpm_module);
-
         if (xpm_module->load_xpm_data == NULL) {
                 g_warning ("gdk-pixbuf XPM module lacks XPM data capability");
                 pixbuf = NULL;
@@ -1977,9 +1947,7 @@ gdk_pixbuf_new_from_xpm_data (const char **data)
                 load_xpm_data = xpm_module->load_xpm_data;
                 pixbuf = (* load_xpm_data) (data);
         }
-        
-        if (locked)
-                _gdk_pixbuf_unlock (xpm_module);
+
         return pixbuf;
 }
 
@@ -2051,7 +2019,6 @@ gdk_pixbuf_real_save (GdkPixbuf     *pixbuf,
 {
         gboolean ret;
         GdkPixbufModule *image_module = NULL;       
-        gboolean locked;
 
         image_module = _gdk_pixbuf_get_named_module (type, error);
 
@@ -2061,8 +2028,6 @@ gdk_pixbuf_real_save (GdkPixbuf     *pixbuf,
         if (!_gdk_pixbuf_load_module (image_module, error))
                 return FALSE;
 
-        locked = _gdk_pixbuf_lock (image_module);
-
         if (image_module->save) {
                 /* save normally */
                 ret = (* image_module->save) (filehandle, pixbuf,
@@ -2084,8 +2049,6 @@ gdk_pixbuf_real_save (GdkPixbuf     *pixbuf,
                 ret = FALSE;
         }
 
-        if (locked)
-                _gdk_pixbuf_unlock (image_module);
         return ret;
 }
 
@@ -2106,7 +2069,6 @@ save_to_callback_with_tmp_file (GdkPixbufModule   *image_module,
         gchar *buf = NULL;
         gsize n;
         gchar *filename = NULL;
-        gboolean locked;
 
         buf = g_try_malloc (TMP_FILE_BUF_SIZE);
         if (buf == NULL) {
@@ -2130,10 +2092,7 @@ save_to_callback_with_tmp_file (GdkPixbufModule   *image_module,
                 goto end;
         }
 
-        locked = _gdk_pixbuf_lock (image_module);
         retval = (image_module->save) (f, pixbuf, keys, values, error);
-        if (locked)
-                _gdk_pixbuf_unlock (image_module);
         if (!retval)
                 goto end;
 
@@ -2181,7 +2140,6 @@ gdk_pixbuf_real_save_to_callback (GdkPixbuf         *pixbuf,
 {
         gboolean ret;
         GdkPixbufModule *image_module = NULL;       
-        gboolean locked;
 
         image_module = _gdk_pixbuf_get_named_module (type, error);
 
@@ -2191,8 +2149,6 @@ gdk_pixbuf_real_save_to_callback (GdkPixbuf         *pixbuf,
         if (!_gdk_pixbuf_load_module (image_module, error))
                 return FALSE;
 
-        locked = _gdk_pixbuf_lock (image_module);
-
         if (image_module->save_to_callback) {
                 /* save normally */
                 ret = (* image_module->save_to_callback) (save_func, user_data, 
@@ -2214,8 +2170,6 @@ gdk_pixbuf_real_save_to_callback (GdkPixbuf         *pixbuf,
                 ret = FALSE;
         }
 
-        if (locked)
-                _gdk_pixbuf_unlock (image_module);
         return ret;
 }
 
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index 8f46deb..2461ec4 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.c
+++ b/gdk-pixbuf/gdk-pixbuf-loader.c
@@ -117,7 +117,6 @@ typedef struct
 {
         GdkPixbufAnimation *animation;
         gboolean closed;
-        gboolean holds_threadlock;
         guchar header_buf[LOADER_HEADER_SIZE];
         gint header_buf_offset;
         GdkPixbufModule *image_module;
@@ -249,9 +248,6 @@ gdk_pixbuf_loader_finalize (GObject *object)
 
         if (!priv->closed) {
                 g_warning ("GdkPixbufLoader finalized without calling gdk_pixbuf_loader_close() - this is not allowed. You must explicitly end the data stream to the loader before dropping the last reference.");
-                if (priv->holds_threadlock) {
-                        _gdk_pixbuf_unlock (priv->image_module);
-                }
         }
         if (priv->animation)
                 g_object_unref (priv->animation);
@@ -442,10 +438,6 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
                         return 0;
                 }
 
-	if (!priv->holds_threadlock) {
-                priv->holds_threadlock = _gdk_pixbuf_lock (priv->image_module);
-        }
-
         priv->context = priv->image_module->begin_load (gdk_pixbuf_loader_size_func,
                                                         gdk_pixbuf_loader_prepare,
                                                         gdk_pixbuf_loader_update,
@@ -803,10 +795,6 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
                 }
   
         priv->closed = TRUE;
-	if (priv->image_module && priv->holds_threadlock) {
-                _gdk_pixbuf_unlock (priv->image_module);
-                priv->holds_threadlock = FALSE;
-        }
 
         if (priv->needs_scale) 
                 {
diff --git a/gdk-pixbuf/gdk-pixbuf-private.h b/gdk-pixbuf/gdk-pixbuf-private.h
index c060bd7..bb6eafa 100644
--- a/gdk-pixbuf/gdk-pixbuf-private.h
+++ b/gdk-pixbuf/gdk-pixbuf-private.h
@@ -82,9 +82,6 @@ struct _GdkPixbufClass {
 
 #ifdef GDK_PIXBUF_ENABLE_BACKEND
 
-gboolean _gdk_pixbuf_lock (GdkPixbufModule *image_module);
-void _gdk_pixbuf_unlock (GdkPixbufModule *image_module);
-
 GdkPixbufModule *_gdk_pixbuf_get_module (guchar *buffer, guint size,
                                          const gchar *filename,
                                          GError **error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]