[vlc-commits] Plugins cache entries are one time use things

Rémi Denis-Courmont git at videolan.org
Thu May 12 23:02:12 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 12 21:51:53 2011 +0300| [468d5f4dba282ed08b3f0c31e3150dd6156afb81] | committer: Rémi Denis-Courmont

Plugins cache entries are one time use things

As the module descriptor is referenced into the main module list
(without copying).

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

 src/modules/cache.c   |   14 ++++++++----
 src/modules/modules.c |   54 ++++++++++++++++++++-----------------------------
 src/modules/modules.h |    2 +-
 3 files changed, 32 insertions(+), 38 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index 53c8a39..66a1b79 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -675,17 +675,21 @@ void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
 /*****************************************************************************
  * CacheFind: finds the cache entry corresponding to a file
  *****************************************************************************/
-module_cache_t *CacheFind( module_bank_t *p_bank,
-                           const char *path, time_t mtime, off_t size )
+module_t *CacheFind( module_bank_t *p_bank,
+                     const char *path, time_t mtime, off_t size )
 {
     module_cache_t **cache = p_bank->pp_loaded_cache;
     size_t n = p_bank->i_loaded_cache;
 
     for( size_t i = 0; i < n; i++ )
         if( !strcmp( cache[i]->path, path )
-         && cache[i]->mtime == mtime &&
-            cache[i]->size == size )
-            return cache[i];
+         && cache[i]->mtime == mtime
+         && cache[i]->size == size )
+       {
+            module_t *module = cache[i]->p_module;
+            cache[i]->p_module = NULL;
+            return module;
+       }
 
     return NULL;
 }
diff --git a/src/modules/modules.c b/src/modules/modules.c
index a1329d7..586b950 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -168,7 +168,8 @@ void module_EndBank( vlc_object_t *p_this, bool b_plugins )
     {
         if( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] )
         {
-            DeleteModule( p_bank,
+            if( unlikely( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->p_module != NULL ) )
+                DeleteModule( p_bank,
                     p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->p_module );
             free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->path );
             free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] );
@@ -956,47 +957,36 @@ static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
                                cache_mode_t mode )
 {
     module_t * p_module = NULL;
-    module_cache_t *p_cache_entry = NULL;
 
     /*
      * Check our plugins cache first then load plugin if needed
      */
-    //if( mode == CACHE_USE )
-    p_cache_entry = CacheFind( p_bank, path, mtime, size );
-
-    if( p_cache_entry == NULL )
-    {
-        p_module = AllocatePlugin( p_this, path );
-        /* FIXME: VLC_PLUGIN_PATH may contains duplicates or aliases.
-         * This needs to be handled correctly even if caching is disabled. */
-    }
-    else
+    if( mode == CACHE_USE )
     {
-        module_config_t *p_item = NULL, *p_end = NULL;
-
-        p_module = p_cache_entry->p_module;
-        p_module->b_loaded = false;
-
-        /* If VLC_PLUGIN_PATH contains duplicate entries... */
-        if( p_module->next != NULL )
-            return 0; /* already taken care of that one */
-
-        /* For now we force loading if the module's config contains
-         * callbacks or actions.
-         * Could be optimized by adding an API call.*/
-        for( p_item = p_module->p_config, p_end = p_item + p_module->confsize;
-             p_item < p_end; p_item++ )
+        p_module = CacheFind( p_bank, path, mtime, size );
+        if( p_module != NULL )
         {
-            if( p_item->i_action )
-            {
-                p_module = AllocatePlugin( p_this, path );
-                break;
-            }
+            /* For now we force loading if the module's config contains
+             * callbacks or actions.
+             * Could be optimized by adding an API call.*/
+            assert( !p_module->b_loaded );
+
+            for( size_t n = p_module->confsize, i = 0; i < n; i++ )
+                if( p_module->p_config[i].i_action )
+                {
+                    DeleteModule( p_bank, p_module );
+                    p_module = AllocatePlugin( p_this, path );
+                    break;
+                }
         }
     }
 
     if( p_module == NULL )
-        return -1;
+    {
+        p_module = AllocatePlugin( p_this, path );
+        if( p_module == NULL )
+            return -1;
+    }
 
     /* We have not already scanned and inserted this module */
     assert( p_module->next == NULL );
diff --git a/src/modules/modules.h b/src/modules/modules.h
index dc67f9c..cd8726e 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -152,6 +152,6 @@ void   CacheMerge (vlc_object_t *, module_t *, module_t *);
 void   CacheDelete(vlc_object_t *, const char *);
 void   CacheLoad  (vlc_object_t *, module_bank_t *, const char *);
 void   CacheSave  (vlc_object_t *, const char *, module_cache_t *const *, size_t);
-module_cache_t * CacheFind (module_bank_t *, const char *, time_t, off_t);
+module_t * CacheFind (module_bank_t *, const char *, time_t, off_t);
 
 #endif /* !LIBVLC_MODULES_H */



More information about the vlc-commits mailing list