changeset 3253:6374d66ee623

proper race condition fix
author William Pitcock <nenolod@atheme-project.org>
date Sun, 05 Aug 2007 20:14:53 -0500
parents eddeaebaf1c7
children 4f4e07f06801 d899694663a7
files src/audacious/playback.c
diffstat 1 files changed, 17 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/playback.c	Mon Aug 06 01:32:41 2007 +0200
+++ b/src/audacious/playback.c	Sun Aug 05 20:14:53 2007 -0500
@@ -181,14 +181,8 @@
 {
     InputPlayback *playback;
     
-    /* this is not very nice, but stop MUST NOT be called until
-       a playback item is created in playback_monitor_thread;
-       we need one to call plugin->stop , otherwise plugins will
-       handle multiple resources for each plugin->play_file without
-       disposing of the previous; this leads to segfault and ui freezes
-       -- giacomo */
-    while ((playback = get_current_input_playback()) == NULL)
-      g_usleep( 20000 );
+    if ((playback = get_current_input_playback()) == NULL)
+        return;
 
     if (ip_data.playing)
     {
@@ -246,21 +240,9 @@
 static gpointer
 playback_monitor_thread(gpointer data)
 {
-    PlaylistEntry *entry = (PlaylistEntry *) data;
-    InputPlayback *playback;
-
-    playback = g_new0(InputPlayback, 1);
-    
-    entry->decoder->output = &psuedo_output_plugin;
+    InputPlayback *playback = (InputPlayback *) data;
 
-    playback->plugin = entry->decoder;
-    playback->output = &psuedo_output_plugin;
-    playback->filename = g_strdup(entry->filename);
-    playback->thread = g_thread_self();
-    
-    set_current_input_playback(playback);
-
-    entry->decoder->play_file(playback);
+    playback->plugin->play_file(playback);
 
     if (!playback->error && ip_data.playing)
         playback_eof();
@@ -307,7 +289,19 @@
     }
 
     ip_data.playing = TRUE;
-    g_thread_create(playback_monitor_thread, entry, TRUE, NULL);
+
+    playback = g_new0(InputPlayback, 1);
+    
+    entry->decoder->output = &psuedo_output_plugin;
+
+    playback->plugin = entry->decoder;
+    playback->output = &psuedo_output_plugin;
+    playback->filename = g_strdup(entry->filename);
+    playback->thread = g_thread_self();
+    
+    set_current_input_playback(playback);
+
+    g_thread_create(playback_monitor_thread, playback, TRUE, NULL);
 
     return TRUE;
 }