[vlc-commits] Keep only one cache file loaded at a time
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 22:04:49 2011 +0300| [ae5e3537d3cb0372c6cef26e046370e2f35d4a68] | committer: Rémi Denis-Courmont
Keep only one cache file loaded at a time
Each cache file is now unloaded as soon as the cache directory scan is
complete. The data is not needed anymore past that point.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ae5e3537d3cb0372c6cef26e046370e2f35d4a68
---
src/modules/cache.c | 54 ++++++++++++++++++++-----------------------------
src/modules/modules.c | 46 ++++++++++++++++++++++++-----------------
src/modules/modules.h | 2 +-
3 files changed, 50 insertions(+), 52 deletions(-)
diff --git a/src/modules/cache.c b/src/modules/cache.c
index 66a1b79..a8fa0b7 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -79,28 +79,28 @@ void CacheDelete( vlc_object_t *obj, const char *dir )
free( path );
}
-/*****************************************************************************
- * LoadPluginsCache: loads the plugins cache file
- *****************************************************************************
+/**
+ * Loads a plugins cache file.
+ *
* This function will load the plugin cache if present and valid. This cache
* will in turn be queried by AllocateAllPlugins() to see if it needs to
* actually load the dynamically loadable module.
* This allows us to only fully load plugins when they are actually used.
- *****************************************************************************/
-void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
+ */
+size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t ***r )
{
char *psz_filename;
FILE *file;
int i_size, i_read;
char p_cachestring[sizeof(CACHE_STRING)];
size_t i_cache;
- module_cache_t **pp_cache = NULL;
int32_t i_file_size, i_marker;
assert( dir != NULL );
+ *r = NULL;
if( asprintf( &psz_filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1 )
- return;
+ return 0;
msg_Dbg( p_this, "loading plugins cache file %s", psz_filename );
@@ -110,7 +110,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
msg_Warn( p_this, "cannot read %s (%m)",
psz_filename );
free( psz_filename );
- return;
+ return 0;
}
free( psz_filename );
@@ -121,7 +121,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
msg_Warn( p_this, "This doesn't look like a valid plugins cache "
"(too short)" );
fclose( file );
- return;
+ return 0;
}
fseek( file, 0, SEEK_END );
@@ -130,7 +130,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
msg_Warn( p_this, "This doesn't look like a valid plugins cache "
"(corrupted size)" );
fclose( file );
- return;
+ return 0;
}
fseek( file, sizeof(i_file_size), SEEK_SET );
@@ -142,7 +142,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
{
msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
fclose( file );
- return;
+ return 0;
}
#ifdef DISTRO_VERSION
@@ -155,7 +155,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
{
msg_Warn( p_this, "This doesn't look like a valid plugins cache" );
fclose( file );
- return;
+ return 0;
}
#endif
@@ -166,7 +166,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
msg_Warn( p_this, "This doesn't look like a valid plugins cache "
"(corrupted header)" );
fclose( file );
- return;
+ return 0;
}
/* Check header marker */
@@ -177,7 +177,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
msg_Warn( p_this, "This doesn't look like a valid plugins cache "
"(corrupted header)" );
fclose( file );
- return;
+ return 0;
}
if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
@@ -185,22 +185,12 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
msg_Warn( p_this, "This doesn't look like a valid plugins cache "
"(file too short)" );
fclose( file );
- return;
+ return 0;
}
- if( i_cache )
- {
- size_t i_already = p_bank->i_loaded_cache;
- pp_cache = realloc( p_bank->pp_loaded_cache,
- (i_already + i_cache) * sizeof(*pp_cache) );
- if( unlikely(pp_cache == NULL) )
- i_cache = 0; /* don't load */
- else
- {
- p_bank->pp_loaded_cache = pp_cache;
- pp_cache += i_already;
- }
- }
+ module_cache_t **pp_cache = malloc( i_cache * sizeof(*pp_cache) );
+ if( pp_cache == NULL )
+ i_cache = 0; /* don't load anything */
#define LOAD_IMMEDIATE(a) \
if( fread( (void *)&a, sizeof(char), sizeof(a), file ) != sizeof(a) ) goto error
@@ -301,10 +291,10 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
LOAD_STRING( p_module->domain );
}
}
- p_bank->i_loaded_cache += i_cache;
-
fclose( file );
- return;
+
+ *r = pp_cache;
+ return i_cache;
error:
@@ -312,7 +302,7 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
/* TODO: cleanup */
fclose( file );
- return;
+ return 0;
}
diff --git a/src/modules/modules.c b/src/modules/modules.c
index 586b950..5a5d241 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -103,8 +103,8 @@ void module_InitBank( vlc_object_t *p_this )
{
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;
+ p_bank->i_cache = 0;
+ p_bank->pp_cache = NULL;
p_bank->head = NULL;
/* Everything worked, attach the object */
@@ -164,18 +164,6 @@ void module_EndBank( vlc_object_t *p_this, bool b_plugins )
vlc_mutex_unlock( &module_lock );
#ifdef HAVE_DYNAMIC_PLUGINS
- while( p_bank->i_loaded_cache-- )
- {
- if( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] )
- {
- 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] );
- }
- }
- free( p_bank->pp_loaded_cache );
while( p_bank->i_cache-- )
{
free( p_bank->pp_cache[p_bank->i_cache]->path );
@@ -868,28 +856,48 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
static void AllocatePluginPath( vlc_object_t *p_this, module_bank_t *p_bank,
const char *path, cache_mode_t mode )
{
+ module_cache_t **cache;
+ size_t count = 0;
size_t offset = p_module_bank->i_cache;
switch( mode )
{
case CACHE_USE:
- CacheLoad( p_this, p_module_bank, path );
+ count = CacheLoad( p_this, path, &cache );
break;
case CACHE_RESET:
CacheDelete( p_this, path );
break;
- default:
+ case CACHE_IGNORE:
msg_Dbg( p_this, "ignoring plugins cache file" );
}
msg_Dbg( p_this, "recursively browsing `%s'", path );
+ /* TODO: pass as argument, remove this hack */
+ p_bank->pp_loaded_cache = cache;
+ p_bank->i_loaded_cache = count;
/* Don't go deeper than 5 subdirectories */
AllocatePluginDir( p_this, p_bank, path, 5, mode );
- if( mode != CACHE_IGNORE )
- CacheSave( p_this, path, p_module_bank->pp_cache + offset,
- p_module_bank->i_cache - offset );
+ switch( mode )
+ {
+ case CACHE_USE:
+ for( size_t i = 0; i < count; i++ )
+ if( likely(cache[i] != NULL) )
+ {
+ if( cache[i]->p_module != NULL )
+ DeleteModule( p_bank, cache[i]->p_module );
+ free( cache[i]->path );
+ free( cache[i] );
+ }
+ free( cache );
+ case CACHE_RESET:
+ CacheSave( p_this, path, p_bank->pp_cache + offset,
+ p_bank->i_cache - offset );
+ case CACHE_IGNORE:
+ break;
+ }
}
/*****************************************************************************
diff --git a/src/modules/modules.h b/src/modules/modules.h
index cd8726e..c972368 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -150,7 +150,7 @@ void module_Unload (module_handle_t);
/* Plugins cache */
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 *);
+size_t CacheLoad (vlc_object_t *, const char *, module_cache_t ***);
void CacheSave (vlc_object_t *, const char *, module_cache_t *const *, size_t);
module_t * CacheFind (module_bank_t *, const char *, time_t, off_t);
More information about the vlc-commits
mailing list