Revision: 1115
http://geeqie.svn.sourceforge.net/geeqie/?rev=1115&view=rev
Author: nadvornik
Date: 2008-08-31 09:20:29 +0000 (Sun, 31 Aug 2008)
Log Message:
-----------
improved thread support in image loader
Modified Paths:
--------------
trunk/src/image-load.c
trunk/src/main.c
Modified: trunk/src/image-load.c
===================================================================
--- trunk/src/image-load.c 2008-08-31 09:13:42 UTC (rev 1114)
+++ trunk/src/image-load.c 2008-08-31 09:20:29 UTC (rev 1115)
@@ -282,6 +282,18 @@
/**************************************************************************************/
/* the following functions may be executed in separate thread */
+static gint image_loader_get_stopping(ImageLoader *il)
+{
+ gint ret;
+ if (!il) return FALSE;
+
+ g_mutex_lock(il->data_mutex);
+ ret = il->stopping;
+ g_mutex_unlock(il->data_mutex);
+
+ return ret;
+}
+
static void image_loader_sync_pixbuf(ImageLoader *il)
{
GdkPixbuf *pb;
@@ -420,15 +432,15 @@
g_object_unref(G_OBJECT(il->loader));
il->loader = NULL;
}
-
+ g_mutex_lock(il->data_mutex);
il->done = TRUE;
+ g_mutex_unlock(il->data_mutex);
}
static void image_loader_setup_loader(ImageLoader *il)
{
g_mutex_lock(il->data_mutex);
il->loader = gdk_pixbuf_loader_new();
- g_mutex_unlock(il->data_mutex);
g_signal_connect(G_OBJECT(il->loader), "area_updated",
G_CALLBACK(image_loader_area_updated_cb), il);
@@ -436,6 +448,7 @@
G_CALLBACK(image_loader_size_cb), il);
g_signal_connect(G_OBJECT(il->loader), "area_prepared",
G_CALLBACK(image_loader_area_prepared_cb), il);
+ g_mutex_unlock(il->data_mutex);
}
@@ -463,7 +476,7 @@
if (!il) return FALSE;
c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
- while (c > 0)
+ while (c > 0 && !image_loader_get_stopping(il))
{
b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
@@ -512,7 +525,7 @@
il->bytes_read += b;
/* read until size is known */
- while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0)
+ while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0
&& !image_loader_get_stopping(il))
{
b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader,
il->mapped_file + il->bytes_read, b, NULL)))
@@ -623,16 +636,6 @@
}
}
-
-/*
-static gint image_loader_setup(ImageLoader *il)
-{
- if (!image_loader_setup_source(il)) return FALSE;
-
- return image_loader_begin(il);
-}
-*/
-
static void image_loader_stop(ImageLoader *il)
{
if (!il) return;
@@ -645,7 +648,9 @@
if (il->thread)
{
+ g_mutex_lock(il->data_mutex);
il->stopping = TRUE;
+ g_mutex_unlock(il->data_mutex);
g_thread_join(il->thread);
}
@@ -696,10 +701,11 @@
ImageLoader *il = data;
gint cont = image_loader_begin(il);
- while (cont && !il->done && !il->stopping)
+ while (cont && !image_loader_get_is_done(il) &&
!image_loader_get_stopping(il))
{
cont = image_loader_continue(il);
}
+ image_loader_stop_loader(il);
return NULL;
}
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2008-08-31 09:13:42 UTC (rev 1114)
+++ trunk/src/main.c 2008-08-31 09:20:29 UTC (rev 1115)
@@ -700,6 +700,8 @@
#ifdef HAVE_GTHREAD
g_thread_init (NULL);
+ gdk_threads_init();
+ gdk_threads_enter();
#endif
/* init execution time counter (debug only) */
@@ -884,7 +886,10 @@
buf = g_build_filename(homedir(), GQ_RC_DIR, ".command", NULL);
remote_connection = remote_server_init(buf, cd);
g_free(buf);
-
+
gtk_main();
+#ifdef HAVE_GTHREAD
+ gdk_threads_leave();
+#endif
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn