]> git.sesse.net Git - vlc/blobdiff - src/misc/objects.c
Remove last occurences of yield in the code and comments.
[vlc] / src / misc / objects.c
index d4f32477381730d24ea2b8f07855022e6ce577c8..52b766e0f3804556f12c4da1bfa70911d63c9879 100644 (file)
@@ -525,7 +525,7 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
     /* If we are of the requested type ourselves, don't look further */
     if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
     {
-        vlc_object_yield( p_this );
+        vlc_object_hold( p_this );
         return p_this;
     }
 
@@ -535,7 +535,7 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
 #ifndef NDEBUG
         if (i_type == VLC_OBJECT_PLAYLIST)
            msg_Err (p_this, "using vlc_object_find(VLC_OBJECT_PLAYLIST) "
-                     "instead of pl_Yield()");
+                     "instead of pl_Hold()");
 #endif
         return vlc_object_find (p_this->p_libvlc, i_type,
                                 (i_mode & ~0x000f)|FIND_CHILD);
@@ -574,7 +574,7 @@ vlc_object_t *vlc_object_find_name( vlc_object_t *p_this,
         && p_this->psz_object_name
         && !strcmp( p_this->psz_object_name, psz_name ) )
     {
-        vlc_object_yield( p_this );
+        vlc_object_hold( p_this );
         return p_this;
     }
 
@@ -613,7 +613,7 @@ vlc_object_t *vlc_object_find_name( vlc_object_t *p_this,
 /**
  * Increment an object reference counter.
  */
-void * __vlc_object_yield( vlc_object_t *p_this )
+void * __vlc_object_hold( vlc_object_t *p_this )
 {
     vlc_object_internals_t *internals = vlc_internals( p_this );
 
@@ -633,6 +633,7 @@ void * __vlc_object_yield( vlc_object_t *p_this )
 void __vlc_object_release( vlc_object_t *p_this )
 {
     vlc_object_internals_t *internals = vlc_internals( p_this );
+    vlc_object_t *parent = NULL;
     bool b_should_destroy;
 
     vlc_spin_lock( &internals->ref_spin );
@@ -651,7 +652,7 @@ void __vlc_object_release( vlc_object_t *p_this )
     /* Slow path */
     /* Remember that we cannot hold the spin while waiting on the mutex */
     vlc_mutex_lock( &structure_lock );
-    /* Take the spin again. Note that another thread may have yielded the
+    /* Take the spin again. Note that another thread may have held the
      * object in the (very short) mean time. */
     vlc_spin_lock( &internals->ref_spin );
     b_should_destroy = --internals->i_refcount == 0;
@@ -659,6 +660,10 @@ void __vlc_object_release( vlc_object_t *p_this )
 
     if( b_should_destroy )
     {
+        /* We have no children */
+        assert (internals->i_children == 0);
+        parent = p_this->p_parent;
+
 #ifndef NDEBUG
         if( VLC_OBJECT(p_this->p_libvlc) == p_this )
         {
@@ -687,25 +692,21 @@ void __vlc_object_release( vlc_object_t *p_this )
         vlc_internals (internals->next)->prev = internals->prev;
         vlc_internals (internals->prev)->next = internals->next;
 
-        /* Detach from parent to protect against FIND_CHILDREN */
-        vlc_object_detach_unlocked (p_this);
-        /* Detach from children to protect against FIND_PARENT */
-        for (int i = 0; i < internals->i_children; i++)
-            internals->pp_children[i]->p_parent = NULL;
+        if (parent)
+            /* Detach from parent to protect against FIND_CHILDREN */
+            vlc_object_detach_unlocked (p_this);
     }
-
     vlc_mutex_unlock( &structure_lock );
 
     if( b_should_destroy )
     {
         int canc;
 
-        free( internals->pp_children );
-        internals->pp_children = NULL;
-        internals->i_children = 0;
         canc = vlc_savecancel ();
         vlc_object_destroy( p_this );
         vlc_restorecancel (canc);
+        if (parent)
+            vlc_object_release (parent);
     }
 }
 
@@ -720,6 +721,7 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
 {
     if( !p_this ) return;
 
+    vlc_object_hold (p_parent);
     vlc_mutex_lock( &structure_lock );
 
     /* Attach the parent to its child */
@@ -785,14 +787,17 @@ static void vlc_object_detach_unlocked (vlc_object_t *p_this)
  *****************************************************************************/
 void __vlc_object_detach( vlc_object_t *p_this )
 {
+    vlc_object_t *p_parent;
     if( !p_this ) return;
 
     vlc_mutex_lock( &structure_lock );
-    if( !p_this->p_parent )
-        msg_Err( p_this, "object is not attached" );
-    else
+    p_parent = p_this->p_parent;
+    if (p_parent)
         vlc_object_detach_unlocked( p_this );
     vlc_mutex_unlock( &structure_lock );
+
+    if (p_parent)
+        vlc_object_release (p_parent);
 }
 
 
@@ -862,7 +867,7 @@ vlc_list_t *__vlc_list_children( vlc_object_t *obj )
     l = NewList( priv->i_children );
     for (int i = 0; i < l->i_count; i++)
     {
-        vlc_object_yield( priv->pp_children[i] );
+        vlc_object_hold( priv->pp_children[i] );
         l->p_values[i].p_object = priv->pp_children[i];
     }
     vlc_mutex_unlock( &structure_lock );
@@ -1062,7 +1067,7 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
         {
             if( p_tmp->i_object_type == i_type )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else
@@ -1078,7 +1083,7 @@ static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
             p_tmp = vlc_internals( p_this )->pp_children[i];
             if( p_tmp->i_object_type == i_type )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else if( vlc_internals( p_tmp )->i_children )
@@ -1116,7 +1121,7 @@ static vlc_object_t * FindObjectName( vlc_object_t *p_this,
             if( p_tmp->psz_object_name
                 && !strcmp( p_tmp->psz_object_name, psz_name ) )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else
@@ -1133,7 +1138,7 @@ static vlc_object_t * FindObjectName( vlc_object_t *p_this,
             if( p_tmp->psz_object_name
                 && !strcmp( p_tmp->psz_object_name, psz_name ) )
             {
-                vlc_object_yield( p_tmp );
+                vlc_object_hold( p_tmp );
                 return p_tmp;
             }
             else if( vlc_internals( p_tmp )->i_children )
@@ -1284,7 +1289,7 @@ static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
         return;
     }
 
-    vlc_object_yield( p_object );
+    vlc_object_hold( p_object );
 
     p_list->p_values[i_index].p_object = p_object;
 
@@ -1306,7 +1311,7 @@ static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
         return;
     }
 
-    vlc_object_yield( p_object );
+    vlc_object_hold( p_object );
 
     p_list->p_values[p_list->i_count].p_object = p_object;
     p_list->i_count++;