]> git.sesse.net Git - vlc/blobdiff - src/playlist/thread.c
playlist: b_cant_sleep is private.
[vlc] / src / playlist / thread.c
index 33f2861ec6eeb9cb2276f1a62023271e628ca15c..5ac497f5085503f9add7d70914b301bfe2f66f56 100644 (file)
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static void RunControlThread ( playlist_t * );
-static void RunPreparse( playlist_preparse_t * );
-static void RunFetcher( playlist_fetcher_t * );
-static void PreparseDestructor( vlc_object_t * );
-static void FetcherDestructor( vlc_object_t * );
+static void* RunControlThread   ( vlc_object_t * );
 
 /*****************************************************************************
  * Main functions for the global thread
@@ -59,64 +55,41 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
     if( !p_playlist ) return;
 
     // Preparse
-    static const char ppname[] = "preparser";
-    p_playlist->p_preparse =
-        vlc_custom_create( p_playlist, sizeof( playlist_preparse_t ),
-                           VLC_OBJECT_GENERIC, ppname );
-    if( !p_playlist->p_preparse )
-    {
-        msg_Err( p_playlist, "unable to create preparser" );
-        vlc_object_release( p_playlist );
-        return;
-    }
-    p_playlist->p_preparse->psz_object_name = strdup( "preparser" );
-    p_playlist->p_preparse->i_waiting = 0;
-    p_playlist->p_preparse->pp_waiting = NULL;
-
-    vlc_object_set_destructor( p_playlist->p_preparse, PreparseDestructor );
-
-    vlc_object_attach( p_playlist->p_preparse, p_playlist );
-    if( vlc_thread_create( p_playlist->p_preparse, "preparser",
-                           RunPreparse, VLC_THREAD_PRIORITY_LOW, true ) )
+    playlist_preparse_t *p_preparse = &pl_priv(p_playlist)->preparse;
+    vlc_mutex_init (&p_preparse->lock);
+    vlc_cond_init (&p_preparse->wait);
+    p_preparse->i_waiting = 0;
+    p_preparse->pp_waiting = NULL;
+
+    if( vlc_clone( &p_preparse->thread, playlist_PreparseLoop, p_preparse,
+                   VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_playlist, "cannot spawn preparse thread" );
-        vlc_object_release( p_playlist->p_preparse );
+        p_preparse->up = false;
         return;
     }
+    p_preparse->up = true;
 
     // Secondary Preparse
-    static const char fname[] = "fetcher";
-    p_playlist->p_fetcher =
-        vlc_custom_create( p_playlist, sizeof( playlist_fetcher_t ),
-                           VLC_OBJECT_GENERIC, fname );
-    if( !p_playlist->p_fetcher )
-    {
-        msg_Err( p_playlist, "unable to create secondary preparser" );
-        vlc_object_release( p_playlist );
-        return;
-    }
-    p_playlist->p_fetcher->psz_object_name = strdup( "fetcher" );
-    p_playlist->p_fetcher->i_waiting = 0;
-    p_playlist->p_fetcher->pp_waiting = NULL;
-    p_playlist->p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist,
-                                                                "album-art" );
-
-    vlc_object_set_destructor( p_playlist->p_fetcher, FetcherDestructor );
-
-    vlc_object_attach( p_playlist->p_fetcher, p_playlist );
-    if( vlc_thread_create( p_playlist->p_fetcher,
-                           "fetcher",
-                           RunFetcher,
-                           VLC_THREAD_PRIORITY_LOW, true ) )
+    playlist_fetcher_t *p_fetcher = &pl_priv(p_playlist)->fetcher;
+    vlc_mutex_init (&p_fetcher->lock);
+    vlc_cond_init (&p_fetcher->wait);
+    p_fetcher->i_waiting = 0;
+    p_fetcher->pp_waiting = NULL;
+    p_fetcher->i_art_policy = var_CreateGetInteger( p_playlist, "album-art" );
+
+    if( vlc_clone( &p_fetcher->thread, playlist_FetcherLoop, p_fetcher,
+                   VLC_THREAD_PRIORITY_LOW ) )
     {
         msg_Err( p_playlist, "cannot spawn secondary preparse thread" );
-        vlc_object_release( p_playlist->p_fetcher );
+        p_fetcher->up = false;
         return;
     }
+    p_fetcher->up = true;
 
     // Start the thread
     if( vlc_thread_create( p_playlist, "playlist", RunControlThread,
-                           VLC_THREAD_PRIORITY_LOW, true ) )
+                           VLC_THREAD_PRIORITY_LOW, false ) )
     {
         msg_Err( p_playlist, "cannot spawn playlist thread" );
         vlc_object_release( p_playlist );
@@ -132,11 +105,11 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
 /**
  * Run the main control thread itself
  */
-static void RunControlThread ( playlist_t *p_playlist )
+static void* RunControlThread ( vlc_object_t *p_this )
 {
-    /* Tell above that we're ready */
-    vlc_thread_ready( p_playlist );
+    playlist_t *p_playlist = (playlist_t*)p_this;
 
+    int canc = vlc_savecancel ();
     vlc_object_lock( p_playlist );
     while( vlc_object_alive( p_playlist ) )
     {
@@ -147,7 +120,7 @@ static void RunControlThread ( playlist_t *p_playlist )
         if( !vlc_object_alive( p_playlist ) )
             break;
 
-        if( p_playlist->b_cant_sleep )
+        if( pl_priv(p_playlist)->b_cant_sleep )
         {
             /* 100 ms is an acceptable delay for playlist operations */
             vlc_object_unlock( p_playlist );
@@ -164,35 +137,6 @@ static void RunControlThread ( playlist_t *p_playlist )
     vlc_object_unlock( p_playlist );
 
     playlist_LastLoop( p_playlist );
-}
-
-/*****************************************************************************
- * Preparse-specific functions
- *****************************************************************************/
-static void RunPreparse ( playlist_preparse_t *p_obj )
-{
-    /* Tell above that we're ready */
-    vlc_thread_ready( p_obj );
-    playlist_PreparseLoop( p_obj );
-}
-
-static void RunFetcher( playlist_fetcher_t *p_obj )
-{
-    /* Tell above that we're ready */
-    vlc_thread_ready( p_obj );
-    playlist_FetcherLoop( p_obj );
-}
-
-static void PreparseDestructor( vlc_object_t * p_this )
-{
-    playlist_preparse_t * p_preparse = (playlist_preparse_t *)p_this;
-    free( p_preparse->pp_waiting );
-    msg_Dbg( p_this, "Destroyed" );
-}
-
-static void FetcherDestructor( vlc_object_t * p_this )
-{
-    playlist_fetcher_t * p_fetcher = (playlist_fetcher_t *)p_this;
-    free( p_fetcher->pp_waiting );
-    msg_Dbg( p_this, "Destroyed" );
+    vlc_restorecancel (canc);
+    return NULL;
 }