]> git.sesse.net Git - vlc/blobdiff - src/misc/objects.c
* ./include/vlc_threads.h, ./src/misc/threads.c: improved the cond_wait
[vlc] / src / misc / objects.c
index c57cacd31e427d0a7d31a846b6436bb53fdd7f7b..6e8d689968d442d9156646d8427016456c3d635e 100644 (file)
@@ -2,7 +2,7 @@
  * objects.c: vlc_object_t handling
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: objects.c,v 1.5 2002/06/02 15:51:30 gbazin Exp $
+ * $Id: objects.c,v 1.11 2002/06/08 14:08:46 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -41,7 +41,7 @@
 
 #include "audio_output.h"
 
-#include "playlist.h"
+#include "vlc_playlist.h"
 #include "interface.h"
 
 /*****************************************************************************
@@ -146,6 +146,9 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
     p_new->pp_children = NULL;
     p_new->i_children = 0;
 
+    vlc_mutex_init( p_new, &p_new->object_lock );
+    vlc_cond_init( p_new, &p_new->object_wait );
+
     //msg_Dbg( p_new, "created object" );
 
     return p_new;
@@ -160,26 +163,51 @@ void * __vlc_object_create( vlc_object_t *p_this, int i_type )
  *****************************************************************************/
 void __vlc_object_destroy( vlc_object_t *p_this )
 {
-    if( p_this->i_refcount )
-    {
-        msg_Err( p_this, "refcount is %i", p_this->i_refcount );
-        vlc_dumpstructure( p_this );
-    }
+    int i_delay = 0;
 
     if( p_this->i_children )
     {
-        msg_Err( p_this, "object still has children" );
+        msg_Err( p_this, "cannot delete object with children" );
         vlc_dumpstructure( p_this );
+        return;
     }
 
     if( p_this->i_parents )
     {
-        msg_Err( p_this, "object still has parents" );
+        msg_Err( p_this, "cannot delete object with parents" );
         vlc_dumpstructure( p_this );
+        return;
+    }
+
+    while( p_this->i_refcount )
+    {
+        i_delay++;
+
+        /* Don't warn immediately ... 100ms seems OK */
+        if( i_delay == 2 )
+        {
+            msg_Warn( p_this, "refcount is %i, delaying before deletion",
+                              p_this->i_refcount );
+        }
+        else if( i_delay == 12 )
+        {
+            msg_Err( p_this, "refcount is %i, I have a bad feeling about this",
+                             p_this->i_refcount );
+        }
+        else if( i_delay == 42 )
+        {
+            msg_Err( p_this, "we waited too long, cancelling destruction" );
+            return;
+        }
+
+        msleep( 100000 );
     }
 
     //msg_Dbg( p_this, "destroyed object" );
 
+    vlc_mutex_destroy( &p_this->object_lock );
+    vlc_cond_destroy( &p_this->object_wait );
+
     free( p_this );
 }