changeset 1274:bcf6dc9564f4

- eliminate gdk_threads_*() based on giacomo's suggestion. - revise signaling of conditional variable.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Mon, 16 Jul 2007 00:39:17 +0900
parents 463729c87300
children b839faa693e2
files src/cue/cuesheet.c
diffstat 1 files changed, 45 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/cue/cuesheet.c	Sun Jul 15 15:00:46 2007 +0200
+++ b/src/cue/cuesheet.c	Mon Jul 16 00:39:17 2007 +0900
@@ -351,31 +351,25 @@
 extern void playback_stop(void);
 extern void mainwin_clear_song_info(void);
 
-static gpointer do_stop(gpointer data)
+static gboolean do_stop(gpointer data)
 {
-//    InputPlayback *playback = (InputPlayback *)data;
-    Playlist *playlist = playlist_get_active();
 #ifdef DEBUG
     g_print("f: do_stop\n");
 #endif
+
     ip_data.stop = TRUE;
     playback_stop();
     ip_data.stop = FALSE;
 
-    PLAYLIST_LOCK(playlist->mutex);
-    gdk_threads_enter();
     mainwin_clear_song_info();
-    gdk_threads_leave();
-    PLAYLIST_UNLOCK(playlist->mutex);
 
 #ifdef DEBUG
     g_print("e: do_stop\n");
 #endif
-    g_thread_exit(NULL);
-    return NULL; //dummy
+    return FALSE; //one-shot
 }
 
-static gpointer do_setpos(gpointer data)
+static gboolean do_setpos(gpointer data)
 {
     Playlist *playlist = playlist_get_active();
     gint pos = playlist_get_position_nolock(playlist);
@@ -388,11 +382,16 @@
 #ifdef DEBUG
     g_print("do_setpos: pos = %d\n\n", pos);
 #endif
-    gdk_threads_enter();
+    /* being done from the main loop thread, does not require locks */
     playlist_set_position(playlist, (guint)pos);
-    gdk_threads_leave();
-    g_thread_exit(NULL);
-    return NULL; //dummy
+
+    /* kick watchdog */
+    g_mutex_lock(cue_mutex);
+    watchdog_state = RUN;
+    g_mutex_unlock(cue_mutex);
+    g_cond_signal(cue_cond);
+
+    return FALSE; //one-shot
 }
 
 static void cue_pause(InputPlayback * data, short p)
@@ -547,7 +546,7 @@
 #ifdef DEBUG
             g_print("e: watchdog exit\n");
 #endif
-            g_mutex_unlock(cue_mutex); // stop() locks cue_mutex.
+            g_mutex_unlock(cue_mutex); // stop() will lock cue_mutex.
             stop(real_ip); // need not to care about real_ip != NULL here.
             g_thread_exit(NULL);
             break;
@@ -576,7 +575,7 @@
         // prev track
         if (time < cue_tracks[cur_cue_track].index)
         {
-            gint incr;
+            static gint incr = 0;
             gint oldpos = cur_cue_track;
 #ifdef DEBUG
             g_print("i: watchdog prev\n");
@@ -591,14 +590,18 @@
                     finetune_seek = time;
             }
 
-            exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
-            g_usleep(TRANSITION_GUARD_TIME);
+            g_mutex_lock(cue_mutex);
+            watchdog_state = STOP;
+            g_mutex_unlock(cue_mutex);
+
+            g_idle_add_full(G_PRIORITY_HIGH , do_setpos, &incr, NULL);
+            continue;
         }
 
         // next track
         if (cur_cue_track + 1 < last_cue_track && time > cue_tracks[cur_cue_track + 1].index)
         {
-            gint incr;
+            static gint incr = 0;
             gint oldpos = cur_cue_track;
 #ifdef DEBUG
             g_print("i: watchdog next\n");
@@ -614,12 +617,17 @@
                     finetune_seek = time;
             }
 
+            g_mutex_lock(cue_mutex);
+            watchdog_state = STOP;
+            g_mutex_unlock(cue_mutex);
+
             if(cfg.stopaftersong) {
-                exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL);
+                g_idle_add_full(G_PRIORITY_HIGH, do_stop, (void *)real_ip, NULL);
+                continue;
             }
             else {
-                exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
-                g_usleep(TRANSITION_GUARD_TIME);
+                g_idle_add_full(G_PRIORITY_HIGH , do_setpos, &incr, NULL);
+                continue;
             }
         }
 
@@ -633,27 +641,32 @@
 #ifdef DEBUG
                     g_print("i: watchdog eof reached\n\n");
 #endif
-                
+                    g_mutex_lock(cue_mutex);
+                    watchdog_state = STOP;
+                    g_mutex_unlock(cue_mutex);
+
                     if(cfg.repeat) {
-                        gint incr = -pos;
-                        exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
-                        g_usleep(TRANSITION_GUARD_TIME);
+                        static gint incr = 0;
+                        incr = -pos;
+                        g_idle_add_full(G_PRIORITY_HIGH , do_setpos, &incr, NULL);
+                        continue;
                     }
                     else {
-                        exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL);
-                        g_usleep(TRANSITION_GUARD_TIME);
+                        g_idle_add_full(G_PRIORITY_HIGH, do_stop, (void *)real_ip, NULL);
+                        continue;
                     }
                 }
                 else {
                     if(cfg.stopaftersong) {
-                        exec_thread = g_thread_create(do_stop, (void *)real_ip, FALSE, NULL);
+                        g_idle_add_full(G_PRIORITY_HIGH, do_stop, (void *)real_ip, NULL);
+                        continue;
                     }
 #ifdef DEBUG
                     g_print("i: watchdog end of cue, advance in playlist\n\n");
 #endif
-                    gint incr = 1;
-                    exec_thread = g_thread_create(do_setpos, &incr, FALSE, NULL);
-                    g_usleep(TRANSITION_GUARD_TIME);
+                    static gint incr = 1;
+                    g_idle_add_full(G_PRIORITY_HIGH , do_setpos, &incr, NULL);
+                    continue;
                 }
             }
         }