Revision: 1131
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1131&view=rev
Author:   nadvornik
Date:     2008-09-03 21:54:49 +0000 (Wed, 03 Sep 2008)

Log Message:
-----------
load thumbnails with lower priority
TODO: maybe implement an exception for visible thumbnails

Modified Paths:
--------------
    trunk/src/image-load.c
    trunk/src/thumb.c
    trunk/src/thumb_standard.c

Modified: trunk/src/image-load.c
===================================================================
--- trunk/src/image-load.c      2008-09-03 21:13:02 UTC (rev 1130)
+++ trunk/src/image-load.c      2008-09-03 21:54:49 UTC (rev 1131)
@@ -701,11 +701,56 @@
 /* execution via thread */
 static GThreadPool *image_loader_thread_pool = NULL;
 
+static GCond *image_loader_prio_cond = NULL;
+static GMutex *image_loader_prio_mutex = NULL;
+static gint image_loader_prio_num = 0;
+
+
+static void image_loader_thread_enter_high()
+{
+       g_mutex_lock(image_loader_prio_mutex);
+       image_loader_prio_num++;
+       g_mutex_unlock(image_loader_prio_mutex);
+}
+
+static void image_loader_thread_leave_high()
+{
+       g_mutex_lock(image_loader_prio_mutex);
+       image_loader_prio_num--;
+       if (image_loader_prio_num == 0) g_cond_signal(image_loader_prio_cond);
+       g_mutex_unlock(image_loader_prio_mutex);
+}
+
+static void image_loader_thread_wait_high()
+{
+       g_mutex_lock(image_loader_prio_mutex);
+       while (image_loader_prio_num) 
+               {
+               g_cond_wait(image_loader_prio_cond, image_loader_prio_mutex);
+               }
+
+       g_mutex_unlock(image_loader_prio_mutex);
+}
+
+
 void image_loader_thread_run(gpointer data, gpointer user_data)
 {
        ImageLoader *il = data;
-       gint cont = image_loader_begin(il);
+       gint cont;
        
+       if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE) 
+               {
+               /* low prio, wait untill high prio tasks finishes */
+               image_loader_thread_wait_high();
+               }
+       else
+               {
+               /* high prio */
+               image_loader_thread_enter_high();
+               }
+       
+       cont = image_loader_begin(il);
+       
        if (!cont && !image_loader_get_pixbuf(il))
                {
                /* 
@@ -718,10 +763,21 @@
        
        while (cont && !image_loader_get_is_done(il) && 
!image_loader_get_stopping(il))
                {
+               if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE) 
+                       {
+                       /* low prio, wait untill high prio tasks finishes */
+                       image_loader_thread_wait_high();
+                       }
                cont = image_loader_continue(il);
                }
        image_loader_stop_loader(il);
 
+       if (il->idle_priority <= G_PRIORITY_DEFAULT_IDLE) 
+               {
+               /* high prio */
+               image_loader_thread_leave_high();
+               }
+
        g_mutex_lock(il->data_mutex);
        il->can_destroy = TRUE;
        g_cond_signal(il->can_destroy_cond);
@@ -743,6 +799,8 @@
         if (!image_loader_thread_pool) 
                {
                image_loader_thread_pool = 
g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
+               image_loader_prio_cond = g_cond_new();
+               image_loader_prio_mutex = g_mutex_new();
                }
 
        il->can_destroy = FALSE; /* ImageLoader can't be freed until 
image_loader_thread_run finishes */
@@ -828,9 +886,8 @@
 {
        if (!il) return;
 
-       g_mutex_lock(il->data_mutex);
+       if (il->thread) return; /* can't change prio if the thread already runs 
*/
        il->idle_priority = priority;
-       g_mutex_unlock(il->data_mutex);
 }
 
 

Modified: trunk/src/thumb.c
===================================================================
--- trunk/src/thumb.c   2008-09-03 21:13:02 UTC (rev 1130)
+++ trunk/src/thumb.c   2008-09-03 21:54:49 UTC (rev 1131)
@@ -273,6 +273,7 @@
        image_loader_free(tl->il);
        tl->il = image_loader_new(fd);
        file_data_unref(fd);
+       image_loader_set_priority(tl->il, G_PRIORITY_LOW);
 
        if (options->thumbnails.fast)
                {

Modified: trunk/src/thumb_standard.c
===================================================================
--- trunk/src/thumb_standard.c  2008-09-03 21:13:02 UTC (rev 1130)
+++ trunk/src/thumb_standard.c  2008-09-03 21:54:49 UTC (rev 1131)
@@ -605,6 +605,7 @@
 static gint thumb_loader_std_setup(ThumbLoaderStd *tl, FileData *fd)
 {
        tl->il = image_loader_new(fd);
+       image_loader_set_priority(tl->il, G_PRIORITY_LOW);
 
        if (options->thumbnails.fast)
                {


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

Reply via email to