]> git.sesse.net Git - vlc/blobdiff - src/playlist/thread.c
psz_object_name should not be const! (else module name aliasing cannot work)
[vlc] / src / playlist / thread.c
index 8d2bd71c66fc827aa23d7d78121827280272cd61..3e2a3d85f59da04449b3de51fff65acebbd64597 100644 (file)
@@ -61,7 +61,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     // Preparse
     p_playlist->p_preparse = vlc_object_create( p_playlist,
                                   sizeof( playlist_preparse_t ) );
-    p_playlist->p_preparse->psz_object_name = "preparser";
+    p_playlist->p_preparse->psz_object_name = strdup( "preparser" );
     if( !p_playlist->p_preparse )
     {
         msg_Err( p_playlist, "unable to create preparser" );
@@ -75,7 +75,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
 
     vlc_object_attach( p_playlist->p_preparse, p_playlist );
     if( vlc_thread_create( p_playlist->p_preparse, "preparser",
-                           RunPreparse, VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
+                           RunPreparse, VLC_THREAD_PRIORITY_LOW, true ) )
     {
         msg_Err( p_playlist, "cannot spawn preparse thread" );
         vlc_object_release( p_playlist->p_preparse );
@@ -85,7 +85,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     // Secondary Preparse
     p_playlist->p_fetcher = vlc_object_create( p_playlist,
                               sizeof( playlist_fetcher_t ) );
-    p_playlist->p_fetcher->psz_object_name = "fetcher";
+    p_playlist->p_fetcher->psz_object_name = strdup( "fetcher" );
     if( !p_playlist->p_fetcher )
     {
         msg_Err( p_playlist, "unable to create secondary preparser" );
@@ -105,7 +105,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     if( vlc_thread_create( p_playlist->p_fetcher,
                            "fetcher",
                            RunFetcher,
-                           VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
+                           VLC_THREAD_PRIORITY_LOW, true ) )
     {
         msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
         vlc_object_release( p_playlist->p_fetcher );
@@ -114,7 +114,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
 
     // Start the thread
     if( vlc_thread_create( p_playlist, "playlist", RunControlThread,
-                           VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
+                           VLC_THREAD_PRIORITY_LOW, true ) )
     {
         msg_Err( p_playlist, "cannot spawn playlist thread" );
         vlc_object_release( p_playlist );
@@ -145,27 +145,35 @@ int playlist_ThreadDestroy( playlist_t * p_playlist )
  */
 static void RunControlThread ( playlist_t *p_playlist )
 {
-    int i_loops = 0;
-
     /* Tell above that we're ready */
     vlc_thread_ready( p_playlist );
-    while( !p_playlist->b_die )
-    {
-        i_loops++;
 
+    vlc_object_lock( p_playlist );
+    while( vlc_object_alive( p_playlist ) )
+    {
+        PL_UNLOCK;
         playlist_MainLoop( p_playlist );
+        PL_LOCK;
+
+        /* The playlist lock has been unlocked, so we can't tell if
+         * someone has killed us in the meantime. Check now. */
+        if( !vlc_object_alive( p_playlist ) )
+            break;
+
         if( p_playlist->b_cant_sleep )
         {
             /* 100 ms is an acceptable delay for playlist operations */
+            PL_UNLOCK;
             msleep( INTF_IDLE_SLEEP*2 );
+            PL_LOCK;
         }
         else
         {
-            PL_LOCK;
-            vlc_cond_wait( &p_playlist->object_wait, &p_playlist->object_lock );
-            PL_UNLOCK;
+            vlc_object_wait( p_playlist );
         }
     }
+    vlc_object_unlock( p_playlist );
+
     playlist_LastLoop( p_playlist );
 }