[vlc-commits] input: remove recursive locking in input_item_Copy()

Rémi Denis-Courmont git at videolan.org
Wed Apr 13 22:29:53 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Apr 13 23:29:39 2016 +0300| [75f9995c3421aea027a46b8ee63b9435b51b04a2] | committer: Rémi Denis-Courmont

input: remove recursive locking in input_item_Copy()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=75f9995c3421aea027a46b8ee63b9435b51b04a2
---

 src/input/item.c |   36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/input/item.c b/src/input/item.c
index e87f089..7a24519 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -993,32 +993,28 @@ input_item_NewWithType( const char *psz_uri, const char *psz_name,
 
 input_item_t *input_item_Copy( input_item_t *p_input )
 {
-    vlc_mutex_lock( &p_input->lock );
+    vlc_meta_t *meta = NULL;
+    input_item_t *item;
 
-    input_item_t *p_new_input =
-        input_item_NewWithType( p_input->psz_uri, p_input->psz_name,
-                                0, NULL, 0, p_input->i_duration,
-                                p_input->i_type );
+    vlc_mutex_lock( &p_input->lock );
 
-    if( p_new_input )
+    item = input_item_NewWithType( p_input->psz_uri, p_input->psz_name,
+                                   0, NULL, 0, p_input->i_duration,
+                                   p_input->i_type );
+    if( likely(item != NULL) && p_input->p_meta != NULL )
     {
-        for( int i = 0 ; i< p_input->i_options; i++ )
-        {
-            input_item_AddOption( p_new_input,
-                                  p_input->ppsz_options[i],
-                                  p_input->optflagv[i] );
-        }
-
-        if( p_input->p_meta )
-        {
-            p_new_input->p_meta = vlc_meta_New();
-            vlc_meta_Merge( p_new_input->p_meta, p_input->p_meta );
-        }
+        meta = vlc_meta_New();
+        vlc_meta_Merge( meta, p_input->p_meta );
     }
-
     vlc_mutex_unlock( &p_input->lock );
 
-    return p_new_input;
+    if( likely(item != NULL) )
+    {   /* No need to lock; no other thread has seen this new item yet. */
+        input_item_CopyOptions( p_input, item );
+        item->p_meta = meta;
+    }
+
+    return item;
 }
 
 struct item_type_entry



More information about the vlc-commits mailing list