[vlc-devel] [PATCH 2/3] misc/xml: only initialize libxml2 once

Marvin Scholz epirat07 at gmail.com
Wed Sep 23 20:52:44 CEST 2020


---
 modules/misc/xml/libxml.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/modules/misc/xml/libxml.c b/modules/misc/xml/libxml.c
index e077139be7f..69637892be9 100644
--- a/modules/misc/xml/libxml.c
+++ b/modules/misc/xml/libxml.c
@@ -52,7 +52,15 @@ static void CatalogAdd( xml_t *p_xml, const char *psz_arg1,
         (unsigned char*)psz_filename );
 }
 
-static vlc_mutex_t lock = VLC_STATIC_MUTEX;
+/*****************************************************************************
+ * libxml2 initialization
+ *****************************************************************************/
+static vlc_once_t xml_init_once_token = VLC_STATIC_ONCE;
+
+static void vlc_libxml_init_once(void)
+{
+    xmlInitParser();
+}
 
 /*****************************************************************************
  * Module initialization
@@ -64,9 +72,7 @@ static int Open( vlc_object_t *p_this )
     if( !xmlHasFeature( XML_WITH_THREAD ) )
         return VLC_EGENERIC;
 
-    vlc_mutex_lock( &lock );
-    xmlInitParser();
-    vlc_mutex_unlock( &lock );
+    vlc_once(&xml_init_once_token, vlc_libxml_init_once);
 
     p_xml->pf_catalog_load = CatalogLoad;
     p_xml->pf_catalog_add  = CatalogAdd;
@@ -232,9 +238,7 @@ static int ReaderOpen( vlc_object_t *p_this )
     if( unlikely(!p_sys) )
         return VLC_ENOMEM;
 
-    vlc_mutex_lock( &lock );
-    xmlInitParser();
-    vlc_mutex_unlock( &lock );
+    vlc_once(&xml_init_once_token, vlc_libxml_init_once);
 
     p_libxml_reader = xmlReaderForIO( StreamRead, NULL, p_reader->p_stream,
                                       NULL, NULL, 0 );
-- 
2.24.3 (Apple Git-128)



More information about the vlc-devel mailing list