[vlc-devel] commit: Module really does not need to be an object ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Sep 21 15:57:02 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sun Sep 21 16:11:24 2008 +0300| [e083d4a76e9f4e5860cc7454ab226da133c30c71] | committer: Rémi Denis-Courmont 

Module really does not need to be an object

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

 src/libvlc.c          |    6 ++++--
 src/modules/modules.c |   36 ++++++++++++++++++------------------
 src/modules/modules.h |    4 +---
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/libvlc.c b/src/libvlc.c
index 07b3ed1..a4f4dcb 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -491,8 +491,10 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         b_exit = true;
     }
 
-    msg_Dbg( p_libvlc, "module bank initialized, found %i modules",
-             vlc_internals( p_module_bank )->i_children );
+    size_t module_count;
+    module_t **list = module_list_get( &module_count );
+    module_list_free( list );
+    msg_Dbg( p_libvlc, "module bank initialized (%u modules)", module_count );
 
     /* Check for help on modules */
     if( (p_tmp = config_GetPsz( p_libvlc, "module" )) )
diff --git a/src/modules/modules.c b/src/modules/modules.c
index be9eb61..1c3001f 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -124,8 +124,7 @@ void __module_InitBank( vlc_object_t *p_this )
 
     if( p_module_bank == NULL )
     {
-        p_bank = vlc_custom_create( p_this, sizeof(module_bank_t),
-                                    VLC_OBJECT_GENERIC, "module bank");
+        p_bank = calloc (1, sizeof(*p_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;
@@ -160,26 +159,24 @@ void __module_InitBank( vlc_object_t *p_this )
  */
 void __module_EndBank( vlc_object_t *p_this )
 {
-    module_t * p_next = NULL;
+    module_bank_t *p_bank;
 
     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
-    if( !p_module_bank )
-    {
-        vlc_mutex_unlock( lock );
-        return;
-    }
-    if( --p_module_bank->i_usage )
+    p_bank = p_module_bank;
+    assert (p_bank != NULL);
+    if( --p_bank->i_usage > 0 )
     {
         vlc_mutex_unlock( lock );
         return;
     }
+    /*FIXME: For thread safety, we need to:
+    p_module_bank = NULL; - immediately, but that will crash the cache */
     vlc_mutex_unlock( lock );
 
     /* Save the configuration */
     config_AutoSaveConfigFile( p_this );
 
 #ifdef HAVE_DYNAMIC_PLUGINS
-# define p_bank p_module_bank
     if( p_bank->b_cache ) CacheSave( p_this );
     while( p_bank->i_loaded_cache-- )
     {
@@ -209,17 +206,13 @@ void __module_EndBank( vlc_object_t *p_this )
         free( p_bank->pp_cache );
         p_bank->pp_cache = NULL;
     }
-# undef p_bank
 #endif
 
-    while( vlc_internals( p_module_bank )->i_children )
-    {
-        p_next = (module_t *)vlc_internals( p_module_bank )->pp_children[0];
-        DeleteModule( p_next, true );
-    }
+    while( p_bank->head != NULL )
+        DeleteModule( p_bank->head, true );
 
-    vlc_object_release( p_module_bank );
-    p_module_bank = NULL;
+    p_module_bank = NULL; /* FIXME: do this inside the lock */
+    free( p_bank );
 }
 
 /**
@@ -1413,6 +1406,13 @@ static void DeleteModule( module_t * p_module, bool b_detach )
 {
     assert( p_module );
 
+    /* Unlist the module (if it is in the list) */
+    module_t **pp_self = &p_module_bank->head;
+    while (*pp_self != NULL && *pp_self != p_module)
+        pp_self = &((*pp_self)->next);
+    if (*pp_self)
+        *pp_self = p_module->next;
+
     /* We free the structures that we strdup()ed in Allocate*Module(). */
 #ifdef HAVE_DYNAMIC_PLUGINS
     if( !p_module->b_builtin )
diff --git a/src/modules/modules.h b/src/modules/modules.h
index baafe45..2516c7c 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -39,9 +39,7 @@
  *****************************************************************************/
 struct module_bank_t
 {
-    VLC_COMMON_MEMBERS
-
-    int              i_usage;
+    unsigned         i_usage;
 
     bool             b_builtins;
     bool             b_plugins;




More information about the vlc-devel mailing list