libvlc: Use a separate lock for media_list_lock and refcounting.
authorPierre d'Herbemont <pdherbemont@free.fr>
Thu, 21 May 2009 06:19:35 +0000 (23:19 -0700)
committerPierre d'Herbemont <pdherbemont@free.fr>
Thu, 21 May 2009 06:19:35 +0000 (23:19 -0700)
Those finer grained locks help the media_list_player.

src/control/libvlc_internal.h
src/control/media_list.c

index 2079d50..ada07d0 100644 (file)
@@ -90,6 +90,7 @@ struct libvlc_media_list_t
     libvlc_instance_t *         p_libvlc_instance;
     int                         i_refcount;
     vlc_mutex_t                 object_lock;
+    vlc_mutex_t                 refcount_lock;
     libvlc_media_t * p_md; /* The media from which the
                                        * mlist comes, if any. */
     vlc_array_t                items;
index 75389c6..e8ae52b 100644 (file)
@@ -170,6 +170,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
     }
 
     vlc_mutex_init( &p_mlist->object_lock );
+    vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock?
 
     vlc_array_init( &p_mlist->items );
     p_mlist->i_refcount = 1;
@@ -188,14 +189,14 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
     libvlc_media_t * p_md;
     int i;
 
-    vlc_mutex_lock( &p_mlist->object_lock );
+    vlc_mutex_lock( &p_mlist->refcount_lock );
     p_mlist->i_refcount--;
     if( p_mlist->i_refcount > 0 )
     {
-        vlc_mutex_unlock( &p_mlist->object_lock );
+        vlc_mutex_unlock( &p_mlist->refcount_lock );
         return;
     }
-    vlc_mutex_unlock( &p_mlist->object_lock );
+    vlc_mutex_unlock( &p_mlist->refcount_lock );
 
     /* Refcount null, time to free */
 
@@ -222,9 +223,9 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
  **************************************************************************/
 void libvlc_media_list_retain( libvlc_media_list_t * p_mlist )
 {
-    vlc_mutex_lock( &p_mlist->object_lock );
+    vlc_mutex_lock( &p_mlist->refcount_lock );
     p_mlist->i_refcount++;
-    vlc_mutex_unlock( &p_mlist->object_lock );
+    vlc_mutex_unlock( &p_mlist->refcount_lock );
 }