[vlc-devel] commit: Don't start the playlist thread if not needed ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Jan 31 00:09:04 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jan 31 01:08:21 2010 +0200| [c029b7afbe9dd9f0f2be5347021f7776d896b73b] | committer: Rémi Denis-Courmont 

Don't start the playlist thread if not needed

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c029b7afbe9dd9f0f2be5347021f7776d896b73b
---

 include/vlc_playlist.h           |    8 ++++----
 src/libvlc.c                     |   12 +++---------
 src/libvlc.h                     |    1 +
 src/libvlccore.sym               |    4 ++--
 src/playlist/control.c           |   32 ++++++++++++++++++++++++++------
 src/playlist/playlist_internal.h |    1 +
 6 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index 926c48e..bcd645f 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -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 )
diff --git a/src/libvlc.c b/src/libvlc.c
index 5cb74d8..961671b 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -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 );
diff --git a/src/libvlc.h b/src/libvlc.h
index 4ab242a..ff1b89f 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -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
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index f856c5f..b3219c0 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -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
diff --git a/src/playlist/control.c b/src/playlist/control.c
index 1f10fb7..3faa472 100644
--- a/src/playlist/control.c
+++ b/src/playlist/control.c
@@ -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 );
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index 3d390e0..7e07a80 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -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,




More information about the vlc-devel mailing list