Don't start the playlist thread if not needed
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 30 Jan 2010 23:08:21 +0000 (01:08 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 30 Jan 2010 23:09:02 +0000 (01:09 +0200)
include/vlc_playlist.h
src/libvlc.c
src/libvlc.h
src/libvlccore.sym
src/playlist/control.c
src/playlist/playlist_internal.h

index 926c48e..bcd645f 100644 (file)
@@ -255,11 +255,11 @@ enum pl_locked_state
 #define PL_UNLOCK playlist_Unlock( p_playlist )
 #define PL_ASSERT_LOCKED playlist_AssertLocked( p_playlist )
 
-VLC_EXPORT( playlist_t *, __pl_Hold, ( vlc_object_t * ) );
-#define pl_Hold( a ) __pl_Hold( VLC_OBJECT(a) )
+VLC_EXPORT( playlist_t *, pl_Hold, ( vlc_object_t * ) );
+#define pl_Hold( a ) pl_Hold( VLC_OBJECT(a) )
 
-VLC_EXPORT( void, __pl_Release, ( vlc_object_t * ) );
-#define pl_Release(a) __pl_Release( VLC_OBJECT(a) )
+VLC_EXPORT( void, pl_Release, ( vlc_object_t * ) );
+#define pl_Release(a) pl_Release( VLC_OBJECT(a) )
 
 /* Playlist control */
 #define playlist_Play(p) playlist_Control(p,PLAYLIST_PLAY, pl_Unlocked )
index 5cb74d8..961671b 100644 (file)
@@ -804,7 +804,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         module_EndBank( p_libvlc, true );
         return VLC_EGENERIC;
     }
-    playlist_Activate( p_playlist );
 
     /* Add service discovery modules */
     psz_modules = var_InheritString( p_libvlc, "services-discovery" );
@@ -987,11 +986,11 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
 void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
 {
     libvlc_priv_t *priv = libvlc_priv (p_libvlc);
-    playlist_t    *p_playlist = priv->p_playlist;
+    playlist_t    *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
 
     /* Deactivate the playlist */
     msg_Dbg( p_libvlc, "deactivating the playlist" );
-    playlist_Deactivate( p_playlist );
+    pl_Deactivate( p_libvlc );
 
     /* Remove all services discovery */
     msg_Dbg( p_libvlc, "removing all services discovery tasks" );
@@ -1010,13 +1009,8 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
     }
 #endif
 
-    /* Free playlist */
-    /* Any thread still running must not assume pl_Hold() succeeds. */
+    /* Free playlist now */
     msg_Dbg( p_libvlc, "removing playlist" );
-
-    libvlc_priv(p_libvlc)->p_playlist = NULL;
-    barrier();  /* FIXME is that correct ? */
-
     vlc_object_release( p_playlist );
 
     stats_TimersDumpAll( p_libvlc );
index 4ab242a..ff1b89f 100644 (file)
@@ -206,6 +206,7 @@ typedef struct libvlc_priv_t
     libvlc_int_t       public_data;
 
     int                i_last_input_id ; ///< Last id of input item
+    bool               playlist_active;
 
     /* Messages */
     msg_bank_t         msg_bank;    ///< The message bank
index f856c5f..b3219c0 100644 (file)
@@ -343,8 +343,8 @@ playlist_Status
 playlist_TreeMove
 playlist_TreeMoveMany
 playlist_Unlock
-__pl_Hold
-__pl_Release
+pl_Hold
+pl_Release
 resolve_xml_special_chars
 sdp_AddAttribute
 sdp_AddMedia
index 1f10fb7..3faa472 100644 (file)
@@ -39,22 +39,34 @@ static int PlaylistVAControl( playlist_t * p_playlist, int i_query, va_list args
  * Playlist control
  *****************************************************************************/
 
-playlist_t *__pl_Hold( vlc_object_t *p_this )
+static vlc_mutex_t global_lock = VLC_STATIC_MUTEX;
+
+#undef pl_Hold
+playlist_t *pl_Hold (vlc_object_t *obj)
 {
     playlist_t *pl;
+    libvlc_int_t *p_libvlc = obj->p_libvlc;
 
-    barrier();
-    pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
+    vlc_mutex_lock (&global_lock);
+    pl = libvlc_priv (p_libvlc)->p_playlist;
+    assert (pl != NULL);
 
-    assert( VLC_OBJECT(pl) != p_this /* This does not make sense to hold the playlist
-    using pl_Hold. use vlc_object_hold in this case */ );
+    if (!libvlc_priv (p_libvlc)->playlist_active)
+    {
+         playlist_Activate (pl);
+         libvlc_priv (p_libvlc)->playlist_active = true;
+    }
 
+    /* The playlist should hold itself with vlc_object_hold() if ever. */
+    assert (VLC_OBJECT (pl) != obj);
     if (pl)
         vlc_object_hold (pl);
+    vlc_mutex_unlock (&global_lock);
     return pl;
 }
 
-void __pl_Release( vlc_object_t *p_this )
+#undef pl_Release
+void pl_Release( vlc_object_t *p_this )
 {
     playlist_t *pl = libvlc_priv (p_this->p_libvlc)->p_playlist;
     assert( pl != NULL );
@@ -66,6 +78,14 @@ void __pl_Release( vlc_object_t *p_this )
     vlc_object_release( pl );
 }
 
+void pl_Deactivate (libvlc_int_t *p_libvlc)
+{
+    vlc_mutex_lock (&global_lock);
+    if (libvlc_priv (p_libvlc)->playlist_active)
+        playlist_Deactivate (libvlc_priv (p_libvlc)->p_playlist);
+    vlc_mutex_unlock (&global_lock);
+}
+
 void playlist_Lock( playlist_t *pl )
 {
     vlc_mutex_lock( &pl_priv(pl)->lock );
index 3d390e0..7e07a80 100644 (file)
@@ -105,6 +105,7 @@ playlist_t *playlist_Create( vlc_object_t * );
 /* */
 void playlist_Activate( playlist_t * );
 void playlist_Deactivate( playlist_t * );
+void pl_Deactivate (libvlc_int_t *);
 
 /* */
 playlist_item_t *playlist_ItemNewFromInput( playlist_t *p_playlist,