Revision: 1116
http://geeqie.svn.sourceforge.net/geeqie/?rev=1116&view=rev
Author: nadvornik
Date: 2008-08-31 10:08:48 +0000 (Sun, 31 Aug 2008)
Log Message:
-----------
use GThreadPool
Modified Paths:
--------------
trunk/src/image-load.c
trunk/src/image-load.h
Modified: trunk/src/image-load.c
===================================================================
--- trunk/src/image-load.c 2008-08-31 09:20:29 UTC (rev 1115)
+++ trunk/src/image-load.c 2008-08-31 10:08:48 UTC (rev 1116)
@@ -89,6 +89,7 @@
#ifdef HAVE_GTHREAD
il->data_mutex = g_mutex_new();
+ il->can_destroy_cond = g_cond_new();
#endif
DEBUG_1("new image loader %p, bufsize=%u idle_loop=%u", il,
il->read_buffer_size, il->idle_read_loop_count);
}
@@ -174,6 +175,7 @@
file_data_unref(il->fd);
#ifdef HAVE_GTHREAD
g_mutex_free(il->data_mutex);
+ g_cond_free(il->can_destroy_cond);
#endif
}
@@ -648,10 +650,11 @@
if (il->thread)
{
+ /* stop loader in the other thread */
g_mutex_lock(il->data_mutex);
il->stopping = TRUE;
+ while (!il->can_destroy) g_cond_wait(il->can_destroy_cond,
il->data_mutex);
g_mutex_unlock(il->data_mutex);
- g_thread_join(il->thread);
}
image_loader_stop_loader(il);
@@ -695,8 +698,9 @@
/**************************************************************************************/
/* execution via thread */
+static GThreadPool *image_loader_thread_pool = NULL;
-gpointer image_loader_thread_run(gpointer data)
+void image_loader_thread_run(gpointer data, gpointer user_data)
{
ImageLoader *il = data;
gint cont = image_loader_begin(il);
@@ -706,19 +710,32 @@
cont = image_loader_continue(il);
}
image_loader_stop_loader(il);
- return NULL;
+
+ g_mutex_lock(il->data_mutex);
+ il->can_destroy = TRUE;
+ g_cond_signal(il->can_destroy_cond);
+ g_mutex_unlock(il->data_mutex);
+
}
+
gint image_loader_start_thread(ImageLoader *il)
{
if (!il) return FALSE;
if (!il->fd) return FALSE;
+ il->thread = TRUE;
+
if (!image_loader_setup_source(il)) return FALSE;
- il->thread = g_thread_create(image_loader_thread_run, il, TRUE, NULL);
- if (!il->thread) return FALSE;
+ if (!image_loader_thread_pool)
+ {
+ image_loader_thread_pool =
g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
+ }
+
+ g_thread_pool_push(image_loader_thread_pool, il, NULL);
+ DEBUG_1("Thread pool num threads: %d",
g_thread_pool_get_num_threads(image_loader_thread_pool));
return TRUE;
}
Modified: trunk/src/image-load.h
===================================================================
--- trunk/src/image-load.h 2008-08-31 09:20:29 UTC (rev 1115)
+++ trunk/src/image-load.h 2008-08-31 10:08:48 UTC (rev 1116)
@@ -46,9 +46,11 @@
gint idle_done_id;
GList *area_param_list;
- GThread *thread;
GMutex *data_mutex;
gint stopping;
+ gint can_destroy;
+ GCond *can_destroy_cond;
+ gboolean thread;
guchar *mapped_file;
gint read_buffer_size;
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