* 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>
*
#include "audio_output.h"
-#include "playlist.h"
+#include "vlc_playlist.h"
#include "interface.h"
/*****************************************************************************
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;
*****************************************************************************/
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 );
}