Changeset 46ffb1cdaefa300605e2802188f57cac5444715a

Show
Ignore:
Timestamp:
05/16/08 14:15:03 (3 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1210940103 +0200
git-parent:

[5d93a7aeb0a773ea3e4c7962f71743537deeb61a]

git-author:
Rafaël Carré <funman@videolan.org> 1210940103 +0200
Message:

Revert "vlc_object_release: cleanup"

This reverts commit c85f868153145c0bd146067dfb9ac2c405f65921.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/misc/objects.c

    r5d93a7a r46ffb1c  
    841841{ 
    842842    vlc_object_internals_t *internals = vlc_internals( p_this ); 
     843    bool b_should_destroy; 
    843844 
    844845    vlc_spin_lock( &internals->ref_spin ); 
    845846    assert( internals->i_refcount > 0 ); 
    846847 
    847     if( --internals->i_refcount
     848    if( internals->i_refcount > 1
    848849    { 
    849850        /* Fast path */ 
    850851        /* There are still other references to the object */ 
     852        internals->i_refcount--; 
    851853        vlc_spin_unlock( &internals->ref_spin ); 
    852854        return; 
     
    854856    vlc_spin_unlock( &internals->ref_spin ); 
    855857 
    856     /* Slow path : object destruction */ 
     858    /* Slow path */ 
    857859    /* Remember that we cannot hold the spin while waiting on the mutex */ 
    858860    vlc_mutex_lock( &structure_lock ); 
    859  
    860     /* Remove the object from the table 
    861      * so that it cannot be encountered by vlc_object_get() */ 
    862     libvlc_global_data_t *p_libvlc_global = vlc_global(); 
    863     int i_index; 
    864  
    865     i_index = FindIndex( p_this, p_libvlc_global->pp_objects, 
    866                          p_libvlc_global->i_objects ); 
    867     REMOVE_ELEM( p_libvlc_global->pp_objects, 
    868                  p_libvlc_global->i_objects, i_index ); 
    869  
    870     /* Detach from parent to protect against FIND_CHILDREN */ 
    871     if (p_this->p_parent) 
    872         vlc_object_detach_unlocked (p_this); 
    873     /* Detach from children to protect against FIND_PARENT */ 
    874     for (int i = 0; i < p_this->i_children; i++) 
    875         p_this->pp_children[i]->p_parent = NULL; 
     861    /* Take the spin again. Note that another thread may have yielded the 
     862     * object in the (very short) mean time. */ 
     863    vlc_spin_lock( &internals->ref_spin ); 
     864    b_should_destroy = --internals->i_refcount == 0; 
     865    vlc_spin_unlock( &internals->ref_spin ); 
     866 
     867    if( b_should_destroy ) 
     868    { 
     869        /* Remove the object from the table 
     870         * so that it cannot be encountered by vlc_object_get() */ 
     871        libvlc_global_data_t *p_libvlc_global = vlc_global(); 
     872        int i_index; 
     873 
     874        i_index = FindIndex( p_this, p_libvlc_global->pp_objects, 
     875                             p_libvlc_global->i_objects ); 
     876        REMOVE_ELEM( p_libvlc_global->pp_objects, 
     877                     p_libvlc_global->i_objects, i_index ); 
     878 
     879        /* Detach from parent to protect against FIND_CHILDREN */ 
     880        if (p_this->p_parent) 
     881            vlc_object_detach_unlocked (p_this); 
     882        /* Detach from children to protect against FIND_PARENT */ 
     883        for (int i = 0; i < p_this->i_children; i++) 
     884            p_this->pp_children[i]->p_parent = NULL; 
     885    } 
    876886 
    877887    vlc_mutex_unlock( &structure_lock ); 
    878888 
    879     vlc_object_destroy( p_this ); 
     889    if( b_should_destroy ) 
     890        vlc_object_destroy( p_this ); 
    880891} 
    881892