changeset 2026:f15664434382 trunk

[svn] rewrite scan thread with g_cond_wait(): - new scan thread is completely event driven. - reduce playlist update latency. - no need for periodical execution.
author yaz
date Thu, 30 Nov 2006 03:16:08 -0800
parents 73471758fc71
children d5a673ad2283
files ChangeLog audacious/main.c audacious/main.h audacious/playlist.c audacious/ui_playlist.c audacious/widgets/Makefile audacious/widgets/playlist_slider.c
diffstat 7 files changed, 98 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 29 19:49:30 2006 -0800
+++ b/ChangeLog	Thu Nov 30 03:16:08 2006 -0800
@@ -1,3 +1,11 @@
+2006-11-30 03:49:30 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [3049]
+  - make sure the mainwin is redrawn correctly when doublesized. reported by Tom St. Denis, closes #674.
+  
+  trunk/audacious/mainwin.c |    4 ++--
+  1 file changed, 2 insertions(+), 2 deletions(-)
+
+
 2006-11-29 21:46:59 +0000  William Pitcock <nenolod@nenolod.net>
   revision [3043]
   - fix conditionals for building build_stamp.c
--- a/audacious/main.c	Wed Nov 29 19:49:30 2006 -0800
+++ b/audacious/main.c	Thu Nov 30 03:16:08 2006 -0800
@@ -386,6 +386,9 @@
 	NULL
 };
 
+GCond *cond_scan;
+GMutex *mutex_scan;
+
 static GSList *
 get_feature_list(void)
 {
@@ -1047,6 +1050,9 @@
 
     gdk_threads_init();
 
+    cond_scan = g_cond_new();
+    mutex_scan = g_mutex_new();
+
     gtk_init_check_ok = gtk_init_check(&argc, &argv);
     /* Now let's parse the command line options first. */
     parse_cmd_line(argc, argv, &options);
@@ -1175,6 +1181,9 @@
 
         GDK_THREADS_LEAVE();
 
+        g_cond_free(cond_scan);
+        g_mutex_free(mutex_scan);
+
         return EXIT_SUCCESS;
     }
     else
--- a/audacious/main.h	Wed Nov 29 19:49:30 2006 -0800
+++ b/audacious/main.h	Thu Nov 30 03:16:08 2006 -0800
@@ -174,6 +174,9 @@
 void make_directory(const gchar * path, mode_t mode);
 void report_error(const gchar *error_text);
 
+extern GCond *cond_scan;
+extern GMutex *mutex_scan;
+
 G_END_DECLS
 
 #endif
--- a/audacious/playlist.c	Wed Nov 29 19:49:30 2006 -0800
+++ b/audacious/playlist.c	Thu Nov 30 03:16:08 2006 -0800
@@ -486,7 +486,10 @@
                              pos);
     PLAYLIST_UNLOCK();
 
+    g_mutex_lock(mutex_scan);
     playlist_get_info_scan_active = TRUE;
+    g_mutex_unlock(mutex_scan);
+    g_cond_signal(cond_scan);
 }
 
 static void
@@ -520,7 +523,10 @@
 
     PLAYLIST_UNLOCK();
 
+    g_mutex_lock(mutex_scan);
     playlist_get_info_scan_active = TRUE;
+    g_mutex_unlock(mutex_scan);
+    g_cond_signal(cond_scan);
 }
 
 static void
@@ -871,6 +877,7 @@
     row = CLAMP(pos - playlistwin_list->pl_num_visible / 2, 0, bottom);
     PLAYLIST_UNLOCK();
     playlistwin_set_toprow(row);
+    g_cond_signal(cond_scan);
 }
 
 void
@@ -2177,6 +2184,7 @@
     while (playlist_get_info_is_going()) {
         PlaylistEntry *entry;
 
+        // on_load
         if (cfg.use_pl_metadata &&
             cfg.get_info_on_load &&
             playlist_get_info_scan_active) {
@@ -2186,7 +2194,8 @@
                 entry = node->data;
 
                 if(entry->tuple && (entry->tuple->length > -1)) {
-                        continue;
+                    update_playlistwin = TRUE;
+                    continue;
                 }
 
                 if (!playlist_entry_get_info(entry)) {
@@ -2195,7 +2204,7 @@
                            Restart. */
                         node = playlist_get();
                 }
-                else if (entry->tuple == NULL && entry->title != NULL && entry->length == -1) {
+                else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) {
                     update_playlistwin = TRUE;
                     if (entry == playlist_position)
                         update_mainwin = TRUE;
@@ -2203,62 +2212,59 @@
                 }
             }
             PLAYLIST_UNLOCK();
-
-            if (!node)
+            
+            if (!node) {
+                g_mutex_lock(mutex_scan);
                 playlist_get_info_scan_active = FALSE;
-        }
+                g_mutex_unlock(mutex_scan);
+            }
+        } // on_load
+
+        // on_demand
         else if (!cfg.get_info_on_load &&
                  cfg.get_info_on_demand &&
                  cfg.playlist_visible &&
                  !cfg.playlist_shaded &&
                  cfg.use_pl_metadata) {
 
-            gboolean found = FALSE;
+            g_mutex_lock(mutex_scan);
+            playlist_get_info_scan_active = FALSE;
+            g_mutex_unlock(mutex_scan);
 
             PLAYLIST_LOCK();
 
             if (!playlist_get()) {
                 PLAYLIST_UNLOCK();
-                g_usleep(1000000);
-                continue;
             }
-
-            for (node = g_list_nth(playlist_get(), playlistwin_get_toprow());
-                 node && playlistwin_item_visible(g_list_position(playlist_get(), node));
-                 node = g_list_next(node)) {
-
-                entry = node->data;
-
-                if(entry->tuple && (entry->tuple->length > -1)) {
-                    continue;
+            else {
+                for (node = g_list_nth(playlist_get(), playlistwin_get_toprow());
+                     node && playlistwin_item_visible(g_list_position(playlist_get(), node));
+                     node = g_list_next(node)) {
+
+                    entry = node->data;
+
+                    if(entry->tuple && (entry->tuple->length > -1)) {
+                        update_playlistwin = TRUE;
+                        continue;
+                    }
+
+                    if (!playlist_entry_get_info(entry)) { 
+                        if (g_list_index(playlist_get(), entry) == -1)
+                            /* Entry disapeared while we
+                               looked it up.  Restart. */
+                            node =
+                                g_list_nth(playlist_get(),
+                                           playlistwin_get_toprow());
+                    }
+                    else if ((entry->tuple != NULL || entry->title != NULL) && entry->length != -1) {
+                        update_playlistwin = TRUE;
+                        if (entry == playlist_position)
+                            update_mainwin = TRUE;
+                    }
                 }
-
-                if (!playlist_entry_get_info(entry)) {
-                    if (g_list_index(playlist_get(), entry) == -1)
-                        /* Entry disapeared while we
-                           looked it up.  Restart. */
-                        node =
-                            g_list_nth(playlist_get(),
-                                       playlistwin_get_toprow());
-                }
-                else if (entry->tuple == NULL && entry->title != NULL && entry->length == -1) {
-                    update_playlistwin = TRUE;
-                    if (entry == playlist_position)
-                        update_mainwin = TRUE;
-                    found = TRUE;
-                    break;
-                }
+                PLAYLIST_UNLOCK();
             }
-
-            PLAYLIST_UNLOCK();
-
-            if (!found) {
-                g_usleep(500000);
-                continue;
-            }
-        }
-        else
-            g_usleep(500000);
+        } // on_demand
 
         if (update_playlistwin) {
             playlistwin_update_list();
@@ -2266,11 +2272,19 @@
         }
 
         if (update_mainwin) {
-
             mainwin_set_info_text();
             update_mainwin = FALSE;
         }
-    }
+
+        if (playlist_get_info_scan_active) {
+            continue;
+        }
+
+        g_mutex_lock(mutex_scan);
+        g_cond_wait(cond_scan, mutex_scan);
+        g_mutex_unlock(mutex_scan);
+
+    }// while
 
     g_thread_exit(NULL);
     return NULL;
@@ -2290,13 +2304,22 @@
     G_LOCK(playlist_get_info_going);
     playlist_get_info_going = FALSE;
     G_UNLOCK(playlist_get_info_going);
+
+    g_mutex_lock(mutex_scan);
+    playlist_get_info_scan_active = TRUE;
+    g_mutex_unlock(mutex_scan);
+
+    g_cond_broadcast(cond_scan);
     g_thread_join(playlist_get_info_thread);
 }
 
 void
 playlist_start_get_info_scan(void)
 {
+    g_mutex_lock(mutex_scan);
     playlist_get_info_scan_active = TRUE;
+    g_mutex_unlock(mutex_scan);
+    g_cond_signal(cond_scan);
 }
 
 void
--- a/audacious/ui_playlist.c	Wed Nov 29 19:49:30 2006 -0800
+++ b/audacious/ui_playlist.c	Thu Nov 30 03:16:08 2006 -0800
@@ -643,15 +643,13 @@
 void
 playlistwin_scroll_up_pushed(void)
 {
-    playlistwin_list->pl_first -= 3;
-    playlistwin_update_list();
+    playlistwin_scroll(-3);
 }
 
 void
 playlistwin_scroll_down_pushed(void)
 {
-    playlistwin_list->pl_first += 3;
-    playlistwin_update_list();
+    playlistwin_scroll(3);
 }
 
 static void
@@ -1462,8 +1460,10 @@
         return FALSE;
     }
 
-    if (refresh)
+    if (refresh) {
+        g_cond_signal(cond_scan);
         playlistwin_update_list();
+    }
 
     return TRUE;
 }
--- a/audacious/widgets/Makefile	Wed Nov 29 19:49:30 2006 -0800
+++ b/audacious/widgets/Makefile	Thu Nov 30 03:16:08 2006 -0800
@@ -40,4 +40,4 @@
 include ../../mk/objective.mk
 
 libwidgets.a: $(OBJECTS)
-	$(AR) cq $@ $(OBJECTS)
+	$(AR) cr $@ $(OBJECTS)
--- a/audacious/widgets/playlist_slider.c	Wed Nov 29 19:49:30 2006 -0800
+++ b/audacious/widgets/playlist_slider.c	Thu Nov 30 03:16:08 2006 -0800
@@ -28,6 +28,8 @@
 #include "skin.h"
 #include "widget.h"
 
+extern GCond *cond_scan;
+
 void
 playlistslider_draw(Widget * w)
 {
@@ -82,7 +84,6 @@
     playlistwin_set_toprow(pos);
 }
 
-
 void
 playlistslider_button_press_cb(GtkWidget * widget,
                                GdkEventButton * event, PlaylistSlider * ps)
@@ -112,6 +113,7 @@
             n *= -1;
         playlistwin_scroll(n);
     }
+    g_cond_signal(cond_scan);
 }
 
 void
@@ -136,6 +138,7 @@
 
     y = event->y - ps->ps_widget.y - ps->ps_drag_y;
     playlistslider_set_pos(ps, y);
+    g_cond_signal(cond_scan);
 }
 
 PlaylistSlider *