]> git.sesse.net Git - vlc/commitdiff
*Partially* fix the module bank initialization serialization
authorRémi Denis-Courmont <rem@videolan.org>
Sun, 30 Mar 2008 14:02:23 +0000 (17:02 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Sun, 30 Mar 2008 14:15:09 +0000 (17:15 +0300)
We should really keep the global "libvlc" lock while initializing the
modules bank. Otherwise, if a second instance is created while the
first one is initializing, it may get an incomplete bank. This commit
addresses the problem w.r.t. the "main" module - only.

src/modules/modules.c
src/modules/modules.h

index 2892b2cbf5de1f895d37d0d1d092e976710f7390..87500c4b55b1939ce4dbc8f24761b4ece173cb20 100644 (file)
@@ -104,8 +104,6 @@ static void   DupModule        ( module_t * );
 static void   UndupModule      ( module_t * );
 #endif
 
-static void module_LoadMain( vlc_object_t *p_this );
-
 /**
  * Init bank
  *
@@ -123,31 +121,34 @@ void __module_InitBank( vlc_object_t *p_this )
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
     vlc_mutex_lock( lockval.p_address );
-    if( p_libvlc_global->p_module_bank )
+
+    if( p_libvlc_global->p_module_bank == NULL )
     {
-        p_libvlc_global->p_module_bank->i_usage++;
-        vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_libvlc_global, "libvlc" );
-        return;
+        p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
+        p_bank->psz_object_name = "module bank";
+        p_bank->i_usage = 1;
+        p_bank->i_cache = p_bank->i_loaded_cache = 0;
+        p_bank->pp_cache = p_bank->pp_loaded_cache = NULL;
+        p_bank->b_cache = p_bank->b_cache_dirty =
+        p_bank->b_cache_delete = VLC_FALSE;
+
+        /* Everything worked, attach the object */
+        p_libvlc_global->p_module_bank = p_bank;
+        vlc_object_attach( p_bank, p_libvlc_global );
+
+        /* Fills the module bank structure with the main module infos.
+         * This is very useful as it will allow us to consider the main
+         * library just as another module, and for instance the configuration
+         * options of main will be available in the module bank structure just
+         * as for every other module. */
+        AllocateBuiltinModule( p_this, vlc_entry__main );
     }
+    else
+        p_libvlc_global->p_module_bank->i_usage++;
+
     vlc_mutex_unlock( lockval.p_address );
     var_Destroy( p_libvlc_global, "libvlc" );
 
-    p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
-    if( !p_bank )
-        return;
-    p_bank->psz_object_name = "module bank";
-    p_bank->i_usage = 1;
-    p_bank->i_cache = p_bank->i_loaded_cache = 0;
-    p_bank->pp_cache = p_bank->pp_loaded_cache = NULL;
-    p_bank->b_cache = p_bank->b_cache_dirty =
-        p_bank->b_cache_delete = VLC_FALSE;
-
-    /* Everything worked, attach the object */
-    p_libvlc_global->p_module_bank = p_bank;
-    vlc_object_attach( p_bank, p_libvlc_global );
-
-    module_LoadMain( p_this );
 }
 
 
@@ -242,37 +243,6 @@ void __module_EndBank( vlc_object_t *p_this )
     p_libvlc_global->p_module_bank = NULL;
 }
 
-/**
- * Load the main program info into the module bank.
- *
- * Fills the module bank structure with the main module infos.
- * This is very useful as it will allow us to consider the main program just
- * as another module, and for instance the configuration options of main will
- * be available in the module bank structure just as for every other module.
- * \param p_this vlc object structure
- * \return nothing
- */
-static void module_LoadMain( vlc_object_t *p_this )
-{
-    vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global();
-
-    var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc_global, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-    if( p_libvlc_global->p_module_bank->b_main )
-    {
-        vlc_mutex_unlock( lockval.p_address );
-        var_Destroy( p_libvlc_global, "libvlc" );
-        return;
-    }
-    p_libvlc_global->p_module_bank->b_main = VLC_TRUE;
-    vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_libvlc_global, "libvlc" );
-
-    AllocateBuiltinModule( p_this, vlc_entry__main );
-}
-
 /**
  * Load all modules which we built with.
  *
index 0d2ab3155aa987ef18a6c0b275c4c0124e744198..a8077d9c96c52742f885109919981c913856b3e2 100644 (file)
@@ -43,7 +43,6 @@ struct module_bank_t
 
     int              i_usage;
 
-    vlc_bool_t       b_main;
     vlc_bool_t       b_builtins;
     vlc_bool_t       b_plugins;