summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf-loader.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2004-11-12 05:34:31 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2004-11-12 05:34:31 +0000
commitc8c94422b5679329fb226a77c007b5b7e89dfc5c (patch)
treeefa6b9636737564d3e525ddc870ad90dffce79d6 /gdk-pixbuf/gdk-pixbuf-loader.c
parentdd5457d6321c13352bcfd77f97a2cf739b808614 (diff)
downloadgdk-pixbuf-c8c94422b5679329fb226a77c007b5b7e89dfc5c.tar.gz
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com> Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters): * gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader is threadsafe. * gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module): Use a lock to make initialization of global data structures threadsafe. * gdk-pixbuf-private.h: * gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock): Auxiliary functions which use another lock to protect threadunsafe image loaders. * gdk-pixbuf-io.c (gdk_pixbuf_real_save): (save_to_callback_with_tmp_file): (gdk_pixbuf_real_save_to_callback): (gdk_pixbuf_new_from_xpm_data): (_gdk_pixbuf_generic_image_load): * gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file): * gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module): (gdk_pixbuf_loader_close): (gdk_pixbuf_loader_finalize): Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock(). * io-ani.c, io-bmp.c, io-gif.c, io-ico.c: * io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c: * io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c: * io-xpm.c: Mark as threadsafe. * io-tiff.c: Remove pointless locking, mark as threadunsafe.
Diffstat (limited to 'gdk-pixbuf/gdk-pixbuf-loader.c')
-rw-r--r--gdk-pixbuf/gdk-pixbuf-loader.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-loader.c b/gdk-pixbuf/gdk-pixbuf-loader.c
index b5c53d603..0ce63605d 100644
--- a/gdk-pixbuf/gdk-pixbuf-loader.c
+++ b/gdk-pixbuf/gdk-pixbuf-loader.c
@@ -50,7 +50,6 @@ static void gdk_pixbuf_loader_finalize (GObject *loader);
static gpointer parent_class = NULL;
static guint pixbuf_loader_signals[LAST_SIGNAL] = { 0 };
-
/* Internal data */
#define LOADER_HEADER_SIZE 128
@@ -59,6 +58,7 @@ typedef struct
{
GdkPixbufAnimation *animation;
gboolean closed;
+ gboolean holds_threadlock;
guchar header_buf[LOADER_HEADER_SIZE];
gint header_buf_offset;
GdkPixbufModule *image_module;
@@ -225,8 +225,12 @@ gdk_pixbuf_loader_finalize (GObject *object)
loader = GDK_PIXBUF_LOADER (object);
priv = loader->priv;
- if (!priv->closed)
+ 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);
@@ -382,6 +386,11 @@ gdk_pixbuf_loader_load_module (GdkPixbufLoader *loader,
return 0;
}
+ if (!priv->holds_threadlock) {
+ _gdk_pixbuf_lock (priv->image_module);
+ priv->holds_threadlock = TRUE;
+ }
+
priv->context = priv->image_module->begin_load (gdk_pixbuf_loader_size_func,
gdk_pixbuf_loader_prepare,
gdk_pixbuf_loader_update,
@@ -736,6 +745,11 @@ gdk_pixbuf_loader_close (GdkPixbufLoader *loader,
}
priv->closed = TRUE;
+ if (priv->image_module) {
+ g_assert (priv->holds_threadlock);
+ _gdk_pixbuf_unlock (priv->image_module);
+ priv->holds_threadlock = FALSE;
+ }
if (priv->needs_scale)
{