Changeset 19bd84c786fecb77531073b697aad4d3c221d15d

Show
Ignore:
Timestamp:
05/07/08 21:41:01 (3 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1210189261 +0300
git-parent:

[7b4e7dc93dd9bf941bcfe2e2911bbf1de86d7bc6]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1210189248 +0300
Message:

Remove useless i_refcount == 0 case and fix a tiny race condition.

When i_refcount drops to zero (under the structure lock), the object is
removed from the objects table before the structure lock is released.
Hence, no objects with a nul refcount can ever be left in the table.

There is an unlikely race condition if another object is removed from
the table right between we unlock the structure lock but before we
return from vlc_object_get() (so that the i_middle offset gets wrong).

Files:

Legend:

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

    rb8909e1 r19bd84c  
    687687    vlc_object_t **pp_objects; 
    688688    libvlc_global_data_t *p_libvlc_global = vlc_global(); 
     689    vlc_object_t *obj = NULL; 
    689690 
    690691    vlc_mutex_lock( &structure_lock ); 
     
    711712            { 
    712713                /* This happens when there are only two remaining objects */ 
    713                 if( pp_objects[i_middle+1]->i_object_id == i_id 
    714                     && vlc_internals( pp_objects[i_middle+1] )->i_refcount > 0 ) 
     714                if( pp_objects[i_middle+1]->i_object_id == i_id ) 
    715715                { 
    716716                    vlc_object_yield_locked( pp_objects[i_middle+1] ); 
    717                     vlc_mutex_unlock( &structure_lock ); 
    718                     return pp_objects[i_middle+1]; 
     717                    obj = pp_objects[i_middle+1]; 
    719718                } 
    720719                break; 
    721720            } 
    722721        } 
    723         else if( vlc_internals( pp_objects[i_middle] )->i_refcount > 0 ) 
     722        else 
    724723        { 
    725724            vlc_object_yield_locked( pp_objects[i_middle] ); 
     
    727726            return pp_objects[i_middle]; 
    728727        } 
    729  
    730         if( i_max == 0 ) 
    731         { 
    732             /* this means that i_max == i_middle, and since we have already 
    733              * tested pp_objects[i_middle]), p_found is properly set. */ 
    734             break; 
    735         } 
    736728    } 
    737729 
    738730    vlc_mutex_unlock( &structure_lock ); 
    739     return NULL
     731    return obj
    740732} 
    741733