Commit d857d877 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Attach object during creation

Attaching an object makes it visible in the hierarchy. This would have
been a problem in some cases with vlc_object_find(), but this function
was removed.
parent 2078838d
...@@ -133,7 +133,8 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length, ...@@ -133,7 +133,8 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
vlc_spin_init (&priv->ref_spin); vlc_spin_init (&priv->ref_spin);
priv->i_refcount = 1; priv->i_refcount = 1;
priv->pf_destructor = NULL; priv->pf_destructor = NULL;
priv->prev = priv->next = priv->first = NULL; priv->prev = NULL;
priv->first = NULL;
vlc_object_t *obj = (vlc_object_t *)(priv + 1); vlc_object_t *obj = (vlc_object_t *)(priv + 1);
obj->psz_object_type = typename; obj->psz_object_type = typename;
...@@ -143,8 +144,21 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length, ...@@ -143,8 +144,21 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
if (likely(parent != NULL)) if (likely(parent != NULL))
{ {
vlc_object_internals_t *papriv = vlc_internals (parent);
obj->i_flags = parent->i_flags; obj->i_flags = parent->i_flags;
obj->p_libvlc = parent->p_libvlc; obj->p_libvlc = parent->p_libvlc;
/* Attach the child to its parent (no lock needed) */
obj->p_parent = vlc_object_hold (parent);
/* Attach the parent to its child (structure lock needed) */
libvlc_lock (obj->p_libvlc);
priv->next = papriv->first;
if (priv->next != NULL)
priv->next->prev = priv;
papriv->first = priv;
libvlc_unlock (obj->p_libvlc);
} }
else else
{ {
...@@ -152,6 +166,8 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length, ...@@ -152,6 +166,8 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
obj->i_flags = 0; obj->i_flags = 0;
obj->p_libvlc = self; obj->p_libvlc = self;
obj->p_parent = NULL;
priv->next = NULL;
vlc_mutex_init (&(libvlc_priv (self)->structure_lock)); vlc_mutex_init (&(libvlc_priv (self)->structure_lock));
/* TODO: should be in src/libvlc.c */ /* TODO: should be in src/libvlc.c */
...@@ -162,7 +178,6 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length, ...@@ -162,7 +178,6 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
var_AddCallback (obj, "vars", DumpCommand, NULL); var_AddCallback (obj, "vars", DumpCommand, NULL);
vlc_restorecancel (canc); vlc_restorecancel (canc);
} }
obj->p_parent = NULL;
memset (obj + 1, 0, length - sizeof (*obj)); memset (obj + 1, 0, length - sizeof (*obj));
return obj; return obj;
...@@ -540,27 +555,15 @@ void vlc_object_release( vlc_object_t *p_this ) ...@@ -540,27 +555,15 @@ void vlc_object_release( vlc_object_t *p_this )
void vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent ) void vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
{ {
if( !p_this ) return; if( !p_this ) return;
if( likely(p_this->p_parent == p_parent) )
return;
vlc_object_internals_t *pap = vlc_internals (p_parent); msg_Err( p_this, "object hierarchy bug:" );
vlc_object_internals_t *priv = vlc_internals (p_this); msg_Err( p_this->p_parent, "created by this object but..." );
msg_Err( p_parent, "...attached to this object" );
priv->prev = NULL; abort();
vlc_object_hold (p_parent);
libvlc_lock (p_this->p_libvlc);
/* Attach the parent to its child */
assert (p_this->p_parent == NULL);
p_this->p_parent = p_parent;
/* Attach the child to its parent */
priv->next = pap->first;
if (priv->next != NULL)
priv->next->prev = priv;
pap->first = priv;
libvlc_unlock (p_this->p_libvlc);
} }
#undef vlc_list_children #undef vlc_list_children
/** /**
* Gets the list of children of an objects, and increment their reference * Gets the list of children of an objects, and increment their reference
......
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