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