Commit 135e63da authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

p_module_bank: move out of vlc_global

parent ca44ef6f
...@@ -182,7 +182,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -182,7 +182,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
if (vlc_threads_init ()) if (vlc_threads_init ())
return NULL; return NULL;
libvlc_global_data_t *p_libvlc_global = vlc_global();
/* Now that the thread system is initialized, we don't have much, but /* Now that the thread system is initialized, we don't have much, but
* at least we have variables */ * at least we have variables */
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
...@@ -191,7 +190,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -191,7 +190,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
/* Guess what CPU we have */ /* Guess what CPU we have */
cpu_flags = CPUCapabilities(); cpu_flags = CPUCapabilities();
/* The module bank will be initialized later */ /* The module bank will be initialized later */
p_libvlc_global->p_module_bank = NULL; p_module_bank = NULL;
} }
/* Allocate a libvlc instance object */ /* Allocate a libvlc instance object */
...@@ -250,7 +249,6 @@ libvlc_int_t * libvlc_InternalCreate( void ) ...@@ -250,7 +249,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
const char *ppsz_argv[] ) const char *ppsz_argv[] )
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global();
libvlc_priv_t *priv = libvlc_priv (p_libvlc); libvlc_priv_t *priv = libvlc_priv (p_libvlc);
char p_capabilities[200]; char p_capabilities[200];
char * p_tmp = NULL; char * p_tmp = NULL;
...@@ -324,7 +322,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -324,7 +322,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/* Check for plugins cache options */ /* Check for plugins cache options */
if( config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0 ) if( config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0 )
{ {
p_libvlc_global->p_module_bank->b_cache_delete = true; p_module_bank->b_cache_delete = true;
} }
/* Will be re-done properly later on */ /* Will be re-done properly later on */
...@@ -416,7 +414,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -416,7 +414,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
psz_language = config_GetPsz( p_libvlc, "language" ); psz_language = config_GetPsz( p_libvlc, "language" );
if( psz_language && *psz_language && strcmp( psz_language, "auto" ) ) if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
{ {
bool b_cache_delete = p_libvlc_global->p_module_bank->b_cache_delete; bool b_cache_delete = p_module_bank->b_cache_delete;
/* Reset the default domain */ /* Reset the default domain */
SetLanguage( psz_language ); SetLanguage( psz_language );
...@@ -429,7 +427,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -429,7 +427,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
if( !config_GetInt( p_libvlc, "ignore-config" ) ) if( !config_GetInt( p_libvlc, "ignore-config" ) )
config_LoadConfigFile( p_libvlc, "main" ); config_LoadConfigFile( p_libvlc, "main" );
config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true ); config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true );
p_libvlc_global->p_module_bank->b_cache_delete = b_cache_delete; p_module_bank->b_cache_delete = b_cache_delete;
} }
free( psz_language ); free( psz_language );
# endif # endif
...@@ -449,7 +447,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -449,7 +447,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
} }
msg_Dbg( p_libvlc, "module bank initialized, found %i modules", msg_Dbg( p_libvlc, "module bank initialized, found %i modules",
vlc_internals( p_libvlc_global->p_module_bank )->i_children ); vlc_internals( p_module_bank )->i_children );
/* Check for help on modules */ /* Check for help on modules */
if( (p_tmp = config_GetPsz( p_libvlc, "module" )) ) if( (p_tmp = config_GetPsz( p_libvlc, "module" )) )
......
...@@ -140,11 +140,13 @@ typedef struct libvlc_global_data_t ...@@ -140,11 +140,13 @@ typedef struct libvlc_global_data_t
{ {
VLC_COMMON_MEMBERS VLC_COMMON_MEMBERS
module_bank_t * p_module_bank; ///< The module bank
char * psz_vlcpath; char * psz_vlcpath;
} libvlc_global_data_t; } libvlc_global_data_t;
/**
* The module bank
*/
extern module_bank_t *p_module_bank;
libvlc_global_data_t *vlc_global (void); libvlc_global_data_t *vlc_global (void);
......
...@@ -874,7 +874,7 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode ) ...@@ -874,7 +874,7 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
* not be shared across LibVLC instances. In the mean time, this ugly * not be shared across LibVLC instances. In the mean time, this ugly
* hack is brought to you by Courmisch. */ * hack is brought to you by Courmisch. */
if (i_type == VLC_OBJECT_MODULE) if (i_type == VLC_OBJECT_MODULE)
return vlc_list_find ((vlc_object_t *)vlc_global ()->p_module_bank, return vlc_list_find ((vlc_object_t *)p_module_bank,
i_type, FIND_CHILD); i_type, FIND_CHILD);
return vlc_list_find (p_this->p_libvlc, i_type, FIND_CHILD); return vlc_list_find (p_this->p_libvlc, i_type, FIND_CHILD);
......
...@@ -105,7 +105,6 @@ void CacheLoad( vlc_object_t *p_this ) ...@@ -105,7 +105,6 @@ void CacheLoad( vlc_object_t *p_this )
int i_cache; int i_cache;
module_cache_t **pp_cache = 0; module_cache_t **pp_cache = 0;
int32_t i_file_size, i_marker; int32_t i_file_size, i_marker;
libvlc_global_data_t *p_libvlc_global = vlc_global();
if( !psz_cachedir ) /* XXX: this should never happen */ if( !psz_cachedir ) /* XXX: this should never happen */
{ {
...@@ -121,7 +120,7 @@ void CacheLoad( vlc_object_t *p_this ) ...@@ -121,7 +120,7 @@ void CacheLoad( vlc_object_t *p_this )
} }
free( psz_cachedir ); free( psz_cachedir );
if( p_libvlc_global->p_module_bank->b_cache_delete ) if( p_module_bank->b_cache_delete )
{ {
#if !defined( UNDER_CE ) #if !defined( UNDER_CE )
unlink( psz_filename ); unlink( psz_filename );
...@@ -224,7 +223,7 @@ void CacheLoad( vlc_object_t *p_this ) ...@@ -224,7 +223,7 @@ void CacheLoad( vlc_object_t *p_this )
return; return;
} }
p_libvlc_global->p_module_bank->i_loaded_cache = 0; p_module_bank->i_loaded_cache = 0;
if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) ) if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
{ {
msg_Warn( p_this, "This doesn't look like a valid plugins cache " msg_Warn( p_this, "This doesn't look like a valid plugins cache "
...@@ -234,7 +233,7 @@ void CacheLoad( vlc_object_t *p_this ) ...@@ -234,7 +233,7 @@ void CacheLoad( vlc_object_t *p_this )
} }
if( i_cache ) if( i_cache )
pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache = pp_cache = p_module_bank->pp_loaded_cache =
malloc( i_cache * sizeof(void *) ); malloc( i_cache * sizeof(void *) );
#define LOAD_IMMEDIATE(a) \ #define LOAD_IMMEDIATE(a) \
...@@ -265,7 +264,7 @@ void CacheLoad( vlc_object_t *p_this ) ...@@ -265,7 +264,7 @@ void CacheLoad( vlc_object_t *p_this )
int i_submodules; int i_submodules;
pp_cache[i] = malloc( sizeof(module_cache_t) ); pp_cache[i] = malloc( sizeof(module_cache_t) );
p_libvlc_global->p_module_bank->i_loaded_cache++; p_module_bank->i_loaded_cache++;
/* Load common info */ /* Load common info */
LOAD_STRING( pp_cache[i]->psz_file ); LOAD_STRING( pp_cache[i]->psz_file );
...@@ -331,7 +330,7 @@ void CacheLoad( vlc_object_t *p_this ) ...@@ -331,7 +330,7 @@ void CacheLoad( vlc_object_t *p_this )
msg_Warn( p_this, "plugins cache not loaded (corrupted)" ); msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
/* TODO: cleanup */ /* TODO: cleanup */
p_libvlc_global->p_module_bank->i_loaded_cache = 0; p_module_bank->i_loaded_cache = 0;
fclose( file ); fclose( file );
return; return;
...@@ -473,7 +472,6 @@ void CacheSave( vlc_object_t *p_this ) ...@@ -473,7 +472,6 @@ void CacheSave( vlc_object_t *p_this )
int i, j, i_cache; int i, j, i_cache;
module_cache_t **pp_cache; module_cache_t **pp_cache;
uint32_t i_file_size = 0; uint32_t i_file_size = 0;
libvlc_global_data_t *p_libvlc_global = vlc_global();
if( !psz_cachedir ) /* XXX: this should never happen */ if( !psz_cachedir ) /* XXX: this should never happen */
{ {
...@@ -530,8 +528,8 @@ void CacheSave( vlc_object_t *p_this ) ...@@ -530,8 +528,8 @@ void CacheSave( vlc_object_t *p_this )
if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1) if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
goto error; goto error;
i_cache = p_libvlc_global->p_module_bank->i_cache; i_cache = p_module_bank->i_cache;
pp_cache = p_libvlc_global->p_module_bank->pp_cache; pp_cache = p_module_bank->pp_cache;
if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1) if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
goto error; goto error;
...@@ -725,10 +723,9 @@ module_cache_t *CacheFind( const char *psz_file, ...@@ -725,10 +723,9 @@ module_cache_t *CacheFind( const char *psz_file,
{ {
module_cache_t **pp_cache; module_cache_t **pp_cache;
int i_cache, i; int i_cache, i;
libvlc_global_data_t *p_libvlc_global = vlc_global();
pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache; pp_cache = p_module_bank->pp_loaded_cache;
i_cache = p_libvlc_global->p_module_bank->i_loaded_cache; i_cache = p_module_bank->i_loaded_cache;
for( i = 0; i < i_cache; i++ ) for( i = 0; i < i_cache; i++ )
{ {
......
...@@ -90,6 +90,8 @@ ...@@ -90,6 +90,8 @@
#include "modules/modules.h" #include "modules/modules.h"
#include "modules/builtin.h" #include "modules/builtin.h"
module_bank_t *p_module_bank;
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -117,11 +119,10 @@ static void UndupModule ( module_t * ); ...@@ -117,11 +119,10 @@ static void UndupModule ( module_t * );
void __module_InitBank( vlc_object_t *p_this ) void __module_InitBank( vlc_object_t *p_this )
{ {
module_bank_t *p_bank = NULL; module_bank_t *p_bank = NULL;
libvlc_global_data_t *p_libvlc_global = vlc_global();
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
if( p_libvlc_global->p_module_bank == NULL ) if( p_module_bank == NULL )
{ {
p_bank = vlc_custom_create( p_this, sizeof(module_bank_t), p_bank = vlc_custom_create( p_this, sizeof(module_bank_t),
VLC_OBJECT_GENERIC, "module bank"); VLC_OBJECT_GENERIC, "module bank");
...@@ -132,8 +133,7 @@ void __module_InitBank( vlc_object_t *p_this ) ...@@ -132,8 +133,7 @@ void __module_InitBank( vlc_object_t *p_this )
p_bank->b_cache_delete = false; p_bank->b_cache_delete = false;
/* Everything worked, attach the object */ /* Everything worked, attach the object */
p_libvlc_global->p_module_bank = p_bank; p_module_bank = p_bank;
vlc_object_attach( p_bank, p_libvlc_global );
/* Fills the module bank structure with the main module infos. /* Fills the module bank structure with the main module infos.
* This is very useful as it will allow us to consider the main * This is very useful as it will allow us to consider the main
...@@ -143,7 +143,7 @@ void __module_InitBank( vlc_object_t *p_this ) ...@@ -143,7 +143,7 @@ void __module_InitBank( vlc_object_t *p_this )
AllocateBuiltinModule( p_this, vlc_entry__main ); AllocateBuiltinModule( p_this, vlc_entry__main );
} }
else else
p_libvlc_global->p_module_bank->i_usage++; p_module_bank->i_usage++;
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
} }
...@@ -160,15 +160,14 @@ void __module_InitBank( vlc_object_t *p_this ) ...@@ -160,15 +160,14 @@ void __module_InitBank( vlc_object_t *p_this )
void __module_EndBank( vlc_object_t *p_this ) void __module_EndBank( vlc_object_t *p_this )
{ {
module_t * p_next = NULL; module_t * p_next = NULL;
libvlc_global_data_t *p_libvlc_global = vlc_global();
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
if( !p_libvlc_global->p_module_bank ) if( !p_module_bank )
{ {
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
return; return;
} }
if( --p_libvlc_global->p_module_bank->i_usage ) if( --p_module_bank->i_usage )
{ {
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
return; return;
...@@ -179,7 +178,7 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -179,7 +178,7 @@ void __module_EndBank( vlc_object_t *p_this )
config_AutoSaveConfigFile( p_this ); config_AutoSaveConfigFile( p_this );
#ifdef HAVE_DYNAMIC_PLUGINS #ifdef HAVE_DYNAMIC_PLUGINS
# define p_bank p_libvlc_global->p_module_bank # define p_bank p_module_bank
if( p_bank->b_cache ) CacheSave( p_this ); if( p_bank->b_cache ) CacheSave( p_this );
while( p_bank->i_loaded_cache-- ) while( p_bank->i_loaded_cache-- )
{ {
...@@ -212,16 +211,14 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -212,16 +211,14 @@ void __module_EndBank( vlc_object_t *p_this )
# undef p_bank # undef p_bank
#endif #endif
vlc_object_detach( p_libvlc_global->p_module_bank ); while( vlc_internals( p_module_bank )->i_children )
while( vlc_internals( p_libvlc_global->p_module_bank )->i_children )
{ {
p_next = (module_t *)vlc_internals( p_libvlc_global->p_module_bank )->pp_children[0]; p_next = (module_t *)vlc_internals( p_module_bank )->pp_children[0];
DeleteModule( p_next, true ); DeleteModule( p_next, true );
} }
vlc_object_release( p_libvlc_global->p_module_bank ); vlc_object_release( p_module_bank );
p_libvlc_global->p_module_bank = NULL; p_module_bank = NULL;
} }
/** /**
...@@ -233,15 +230,13 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -233,15 +230,13 @@ void __module_EndBank( vlc_object_t *p_this )
*/ */
void __module_LoadBuiltins( vlc_object_t * p_this ) void __module_LoadBuiltins( vlc_object_t * p_this )
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global();
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
if( p_libvlc_global->p_module_bank->b_builtins ) if( p_module_bank->b_builtins )
{ {
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
return; return;
} }
p_libvlc_global->p_module_bank->b_builtins = true; p_module_bank->b_builtins = true;
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
msg_Dbg( p_this, "checking builtin modules" ); msg_Dbg( p_this, "checking builtin modules" );
...@@ -259,24 +254,22 @@ void __module_LoadBuiltins( vlc_object_t * p_this ) ...@@ -259,24 +254,22 @@ void __module_LoadBuiltins( vlc_object_t * p_this )
void __module_LoadPlugins( vlc_object_t * p_this ) void __module_LoadPlugins( vlc_object_t * p_this )
{ {
#ifdef HAVE_DYNAMIC_PLUGINS #ifdef HAVE_DYNAMIC_PLUGINS
libvlc_global_data_t *p_libvlc_global = vlc_global();
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
if( p_libvlc_global->p_module_bank->b_plugins ) if( p_module_bank->b_plugins )
{ {
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
return; return;
} }
p_libvlc_global->p_module_bank->b_plugins = true; p_module_bank->b_plugins = true;
vlc_mutex_unlock( lock ); vlc_mutex_unlock( lock );
msg_Dbg( p_this, "checking plugin modules" ); msg_Dbg( p_this, "checking plugin modules" );
if( config_GetInt( p_this, "plugins-cache" ) ) if( config_GetInt( p_this, "plugins-cache" ) )
p_libvlc_global->p_module_bank->b_cache = true; p_module_bank->b_cache = true;
if( p_libvlc_global->p_module_bank->b_cache || if( p_module_bank->b_cache ||
p_libvlc_global->p_module_bank->b_cache_delete ) CacheLoad( p_this ); p_module_bank->b_cache_delete ) CacheLoad( p_this );
AllocateAllPlugins( p_this ); AllocateAllPlugins( p_this );
#endif #endif
...@@ -1188,8 +1181,6 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file, ...@@ -1188,8 +1181,6 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
if( p_module ) if( p_module )
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global();
/* Everything worked fine ! /* Everything worked fine !
* The module is ready to be added to the list. */ * The module is ready to be added to the list. */
p_module->b_builtin = false; p_module->b_builtin = false;
...@@ -1197,12 +1188,12 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file, ...@@ -1197,12 +1188,12 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
/* msg_Dbg( p_this, "plugin \"%s\", %s", /* msg_Dbg( p_this, "plugin \"%s\", %s",
p_module->psz_object_name, p_module->psz_longname ); */ p_module->psz_object_name, p_module->psz_longname ); */
vlc_object_attach( p_module, p_libvlc_global->p_module_bank ); vlc_object_attach( p_module, p_module_bank );
if( !p_libvlc_global->p_module_bank->b_cache ) if( !p_module_bank->b_cache )
return 0; return 0;
#define p_bank p_libvlc_global->p_module_bank #define p_bank p_module_bank
/* Add entry to cache */ /* Add entry to cache */
p_bank->pp_cache = p_bank->pp_cache =
realloc( p_bank->pp_cache, (p_bank->i_cache + 1) * sizeof(void *) ); realloc( p_bank->pp_cache, (p_bank->i_cache + 1) * sizeof(void *) );
...@@ -1363,7 +1354,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this, ...@@ -1363,7 +1354,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
/* msg_Dbg( p_this, "builtin \"%s\", %s", /* msg_Dbg( p_this, "builtin \"%s\", %s",
p_module->psz_object_name, p_module->psz_longname ); */ p_module->psz_object_name, p_module->psz_longname ); */
vlc_object_attach( p_module, vlc_global()->p_module_bank ); vlc_object_attach( p_module, p_module_bank );
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment