]> git.sesse.net Git - vlc/commitdiff
Remove useless i_refcount == 0 case and fix a tiny race condition.
authorRémi Denis-Courmont <rem@videolan.org>
Wed, 7 May 2008 19:40:48 +0000 (22:40 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Wed, 7 May 2008 19:41:01 +0000 (22:41 +0300)
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).

src/misc/objects.c

index 97db4e128dee83fd9c99a263b9d605f1f6a7c051..64862e0f857d09a690ae86499ad534436651c295 100644 (file)
@@ -686,6 +686,7 @@ void * vlc_object_get( int i_id )
     int i_max, i_middle;
     vlc_object_t **pp_objects;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
+    vlc_object_t *obj = NULL;
 
     vlc_mutex_lock( &structure_lock );
 
@@ -710,33 +711,24 @@ void * vlc_object_get( int i_id )
             else
             {
                 /* This happens when there are only two remaining objects */
-                if( pp_objects[i_middle+1]->i_object_id == i_id
-                    && vlc_internals( pp_objects[i_middle+1] )->i_refcount > 0 )
+                if( pp_objects[i_middle+1]->i_object_id == i_id )
                 {
                     vlc_object_yield_locked( pp_objects[i_middle+1] );
-                    vlc_mutex_unlock( &structure_lock );
-                    return pp_objects[i_middle+1];
+                    obj = pp_objects[i_middle+1];
                 }
                 break;
             }
         }
-        else if( vlc_internals( pp_objects[i_middle] )->i_refcount > 0 )
+        else
         {
             vlc_object_yield_locked( pp_objects[i_middle] );
             vlc_mutex_unlock( &structure_lock );
             return pp_objects[i_middle];
         }
-
-        if( i_max == 0 )
-        {
-            /* this means that i_max == i_middle, and since we have already
-             * tested pp_objects[i_middle]), p_found is properly set. */
-            break;
-        }
     }
 
     vlc_mutex_unlock( &structure_lock );
-    return NULL;
+    return obj;
 }
 
 /**