[vlc-devel] commit: playlist: Properly clean the playlist using the object destructor. (Pierre d'Herbemont )

git version control git at videolan.org
Wed Mar 26 17:36:12 CET 2008


vlc | branch: master | Pierre d'Herbemont <pdherbemont at videolan.org> | Wed Mar 26 10:15:03 2008 +0100| [624a1e2a3bbd0213583f003dab15e69354520212]

playlist: Properly clean the playlist using the object destructor.

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

 src/playlist/engine.c |   29 +++++++++++++++++++++++++++--
 src/playlist/thread.c |   26 ++------------------------
 2 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 07f0b72..c1b9b97 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -38,6 +38,7 @@
  * Local prototypes
  *****************************************************************************/
 static void VariablesInit( playlist_t *p_playlist );
+static void playlist_Destructor( vlc_object_t * p_this );
 
 static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
                            vlc_value_t oldval, vlc_value_t newval, void *a )
@@ -155,6 +156,9 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
     p_playlist->b_auto_preparse = VLC_FALSE;
     playlist_MLLoad( p_playlist );
     p_playlist->b_auto_preparse = VLC_TRUE;
+
+    vlc_object_set_destructor( p_playlist, playlist_Destructor );
+
     return p_playlist;
 }
 
@@ -167,6 +171,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
  */
 void playlist_Destroy( playlist_t *p_playlist )
 {
+    /* XXX: should go in the playlist destructor */
     var_Destroy( p_playlist, "intf-change" );
     var_Destroy( p_playlist, "item-change" );
     var_Destroy( p_playlist, "playlist-current" );
@@ -179,11 +184,31 @@ void playlist_Destroy( playlist_t *p_playlist )
     var_Destroy( p_playlist, "loop" );
     var_Destroy( p_playlist, "activity" );
 
-    vlc_mutex_destroy( &p_playlist->gc_lock );
-    vlc_object_detach( p_playlist );
     vlc_object_release( p_playlist );
 }
 
+static void playlist_Destructor( vlc_object_t * p_this )
+{
+    playlist_t * p_playlist = (playlist_t *)p_this;
+
+    // Kill preparser
+    if( p_playlist->p_preparse )
+    {
+        vlc_object_release( p_playlist->p_preparse );
+    }
+
+    // Kill meta fetcher
+    if( p_playlist->p_fetcher )
+    {
+        vlc_object_release( p_playlist->p_fetcher );
+    }
+
+    // Stats
+    vlc_mutex_destroy( &p_playlist->p_stats->lock );
+    if( p_playlist->p_stats )
+        free( p_playlist->p_stats );
+}
+
 /* Destroy remaining objects */
 static void ObjectGarbageCollector( playlist_t *p_playlist, vlc_bool_t b_force )
 {
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 55bd4aa..69f62a3 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -71,6 +71,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";
     if( !p_playlist->p_preparse )
     {
         msg_Err( p_playlist, "unable to create preparser" );
@@ -94,6 +95,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";
     if( !p_playlist->p_fetcher )
     {
         msg_Err( p_playlist, "unable to create secondary preparser" );
@@ -144,31 +146,7 @@ void __playlist_ThreadCreate( vlc_object_t *p_parent )
  */
 int playlist_ThreadDestroy( playlist_t * p_playlist )
 {
-    // Tell playlist to go to last loop
-    vlc_object_kill( p_playlist );
-
-    // Kill preparser
-    if( p_playlist->p_preparse )
-    {
-        vlc_object_release( p_playlist->p_preparse );
-    }
-
-    // Kill meta fetcher
-    if( p_playlist->p_fetcher )
-    {
-        vlc_object_release( p_playlist->p_fetcher );
-    }
-
-    // Wait for thread to complete
-    vlc_thread_join( p_playlist );
-
-    // Stats
-    vlc_mutex_destroy( &p_playlist->p_stats->lock );
-    if( p_playlist->p_stats )
-        free( p_playlist->p_stats );
-
     playlist_Destroy( p_playlist );
-
     return VLC_SUCCESS;
 }
 




More information about the vlc-devel mailing list