]> git.sesse.net Git - vlc/commitdiff
objects: Allow certain operations when the object refcount is zero (read, allow certa...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 26 Mar 2008 09:22:29 +0000 (10:22 +0100)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 26 Mar 2008 16:36:06 +0000 (17:36 +0100)
src/misc/objects.c

index 3b7c24bdd79beaab76b945abceb97f351d3411d7..4e5127cdc66656de38f9b8afa979c4b0d5308c69 100644 (file)
@@ -393,6 +393,18 @@ static void vlc_object_destroy( vlc_object_t *p_this )
     /* Automatically detach the object from its parents */
     if( p_this->p_parent ) vlc_object_detach( p_this );
 
+
+    /* Send a kill to the object's thread if applicable */
+    vlc_object_kill( p_this );
+
+    /* If we are running on a thread, wait until it ends */
+    if( p_priv->b_thread )
+        vlc_thread_join( p_this );
+
+    /* Call the custom "subclass" destructor */
+    if( p_priv->pf_destructor )
+        p_priv->pf_destructor( p_this );
+
     /* Sanity checks */
     if( p_this->i_children )
     {
@@ -416,19 +428,6 @@ static void vlc_object_destroy( vlc_object_t *p_this )
         abort();
     }
 
-
-    /* Send a kill to the object's thread if applicable */
-    vlc_object_kill( p_this );
-
-    /* If we are running on a thread, wait until it ends */
-    if( p_priv->b_thread )
-        vlc_thread_join( p_this );
-
-    /* Call the custom "subclass" destructor */
-    if( p_priv->pf_destructor )
-        p_priv->pf_destructor( p_this );
-
-
     /* Destroy the associated variables, starting from the end so that
      * no memmove calls have to be done. */
     while( p_priv->i_vars )
@@ -764,7 +763,8 @@ void * vlc_object_get( int i_id )
             else
             {
                 /* This happens when there are only two remaining objects */
-                if( pp_objects[i_middle+1]->i_object_id == i_id )
+                if( pp_objects[i_middle+1]->i_object_id == i_id
+                    && pp_objects[i_middle+1]->p_internals->i_refcount > 0 )
                 {
                     vlc_object_yield_locked( pp_objects[i_middle+1] );
                     vlc_mutex_unlock( &structure_lock );
@@ -773,7 +773,7 @@ void * vlc_object_get( int i_id )
                 break;
             }
         }
-        else
+        else if( pp_objects[i_middle]->p_internals->i_refcount > 0 )
         {
             vlc_object_yield_locked( pp_objects[i_middle] );
             vlc_mutex_unlock( &structure_lock );
@@ -805,11 +805,9 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
 
     vlc_mutex_lock( &structure_lock );
 
-    /* Avoid obvious freed object uses */
-    assert( p_this->p_internals->i_refcount > 0 );
-
     /* If we are of the requested type ourselves, don't look further */
-    if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
+    if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type
+        && p_this->p_internals->i_refcount > 0 )
     {
         vlc_object_yield_locked( p_this );
         vlc_mutex_unlock( &structure_lock );
@@ -865,7 +863,8 @@ void * __vlc_object_find_name( vlc_object_t *p_this, const char *psz_name,
     /* If have the requested name ourselves, don't look further */
     if( !(i_mode & FIND_STRICT)
         && p_this->psz_object_name
-        && !strcmp( p_this->psz_object_name, psz_name ) )
+        && !strcmp( p_this->psz_object_name, psz_name )
+        && p_this->p_internals->i_refcount > 0 )
     {
         vlc_object_yield_locked( p_this );
         vlc_mutex_unlock( &structure_lock );
@@ -1041,9 +1040,6 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
 
     vlc_mutex_lock( &structure_lock );
 
-    /* Avoid obvious freed object uses */
-    assert( p_this->p_internals->i_refcount > 0 );
-
     /* Look for the objects */
     switch( i_mode & 0x000f )
     {
@@ -1350,7 +1346,8 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
         p_tmp = p_this->p_parent;
         if( p_tmp )
         {
-            if( p_tmp->i_object_type == i_type )
+            if( p_tmp->i_object_type == i_type
+                && p_tmp->p_internals->i_refcount > 0 )
             {
                 vlc_object_yield_locked( p_tmp );
                 return p_tmp;
@@ -1366,7 +1363,8 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
         for( i = p_this->i_children; i--; )
         {
             p_tmp = p_this->pp_children[i];
-            if( p_tmp->i_object_type == i_type )
+            if( p_tmp->i_object_type == i_type
+                && p_tmp->p_internals->i_refcount > 0 )
             {
                 vlc_object_yield_locked( p_tmp );
                 return p_tmp;
@@ -1404,7 +1402,8 @@ static vlc_object_t * FindObjectName( vlc_object_t *p_this,
         if( p_tmp )
         {
             if( p_tmp->psz_object_name
-                && !strcmp( p_tmp->psz_object_name, psz_name ) )
+                && !strcmp( p_tmp->psz_object_name, psz_name )
+                && p_tmp->p_internals->i_refcount > 0 )
             {
                 vlc_object_yield_locked( p_tmp );
                 return p_tmp;
@@ -1421,7 +1420,8 @@ static vlc_object_t * FindObjectName( vlc_object_t *p_this,
         {
             p_tmp = p_this->pp_children[i];
             if( p_tmp->psz_object_name
-                && !strcmp( p_tmp->psz_object_name, psz_name ) )
+                && !strcmp( p_tmp->psz_object_name, psz_name )
+                && p_tmp->p_internals->i_refcount > 0 )
             {
                 vlc_object_yield_locked( p_tmp );
                 return p_tmp;