[vlc-devel] commit: Allow vlc_object_attach to reparent directly ( Rémi Denis-Courmont )

git version control git at videolan.org
Thu Jan 28 21:17:47 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jan 28 22:09:39 2010 +0200| [5d90ca7cc21e1ba7691765e232c047668bb81578] | committer: Rémi Denis-Courmont 

Allow vlc_object_attach to reparent directly

This saves one unlock/lock cycle, and makes sure that the reparented
object remains in the tree at all times. This does not fix the race in
reparenting, but it reduces its window of opportunity.

This also makes vlc_object_detach() essentially redumdant with
vlc_object_release() and vlc_object_attach().

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

 src/misc/objects.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index fb1dc39..725f10b 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -611,6 +611,7 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
 
     vlc_object_internals_t *pap = vlc_internals (p_parent);
     vlc_object_internals_t *priv = vlc_internals (p_this);
+    vlc_object_t *p_old_parent;
 
     priv->prev = NULL;
     vlc_object_hold (p_parent);
@@ -630,8 +631,11 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
                   priv->old_parent, p_parent);
 #endif
 
+    p_old_parent = p_this->p_parent;
+    if (p_old_parent)
+        vlc_object_detach_unlocked (p_this);
+
     /* Attach the parent to its child */
-    assert (!p_this->p_parent);
     p_this->p_parent = p_parent;
 
     /* Attach the child to its parent */
@@ -640,6 +644,9 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
         priv->next->prev = priv;
     pap->first = priv;
     libvlc_unlock (p_this->p_libvlc);
+
+    if (p_old_parent)
+        vlc_object_release (p_old_parent);
 }
 
 




More information about the vlc-devel mailing list