Commit 5d90ca7c authored by Rémi Denis-Courmont's avatar 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().
parent c66586a5
...@@ -611,6 +611,7 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent ) ...@@ -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 *pap = vlc_internals (p_parent);
vlc_object_internals_t *priv = vlc_internals (p_this); vlc_object_internals_t *priv = vlc_internals (p_this);
vlc_object_t *p_old_parent;
priv->prev = NULL; priv->prev = NULL;
vlc_object_hold (p_parent); vlc_object_hold (p_parent);
...@@ -630,8 +631,11 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *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); priv->old_parent, p_parent);
#endif #endif
p_old_parent = p_this->p_parent;
if (p_old_parent)
vlc_object_detach_unlocked (p_this);
/* Attach the parent to its child */ /* Attach the parent to its child */
assert (!p_this->p_parent);
p_this->p_parent = p_parent; p_this->p_parent = p_parent;
/* Attach the child to its 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 ) ...@@ -640,6 +644,9 @@ void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
priv->next->prev = priv; priv->next->prev = priv;
pap->first = priv; pap->first = priv;
libvlc_unlock (p_this->p_libvlc); libvlc_unlock (p_this->p_libvlc);
if (p_old_parent)
vlc_object_release (p_old_parent);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment