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

module_t: use GC subsystem instead of objects

Modules have no threads, no variables (!= config items) and
no plugin instances...
parent cc2d7b41
...@@ -398,7 +398,7 @@ static int CacheLoadConfig( module_t *p_module, FILE *file ) ...@@ -398,7 +398,7 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
p_module->p_config[i].b_dirty = false; p_module->p_config[i].b_dirty = false;
p_module->p_config[i].p_lock = &(vlc_internals(p_module)->lock); p_module->p_config[i].p_lock = &p_module->lock;
if( p_module->p_config[i].i_list ) if( p_module->p_config[i].i_list )
{ {
...@@ -586,15 +586,11 @@ void CacheSave( vlc_object_t *p_this ) ...@@ -586,15 +586,11 @@ void CacheSave( vlc_object_t *p_this )
SAVE_STRING( pp_cache[i]->p_module->psz_filename ); SAVE_STRING( pp_cache[i]->p_module->psz_filename );
i_submodule = vlc_internals( pp_cache[i]->p_module )->i_children; i_submodule = pp_cache[i]->p_module->submodule_count;
SAVE_IMMEDIATE( i_submodule ); SAVE_IMMEDIATE( i_submodule );
for( i_submodule = 0; for( module_t *p_module = pp_cache[i]->p_module->submodule;
i_submodule < (unsigned)vlc_internals( pp_cache[i]->p_module)->i_children; p_module != NULL; p_module = p_module->next )
i_submodule++ )
{ {
module_t *p_module =
(module_t *)vlc_internals( pp_cache[i]->p_module )->pp_children[i_submodule];
SAVE_STRING( p_module->psz_object_name ); SAVE_STRING( p_module->psz_object_name );
SAVE_STRING( p_module->psz_shortname ); SAVE_STRING( p_module->psz_shortname );
SAVE_STRING( p_module->psz_longname ); SAVE_STRING( p_module->psz_longname );
...@@ -689,19 +685,23 @@ error: ...@@ -689,19 +685,23 @@ error:
*****************************************************************************/ *****************************************************************************/
void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module ) void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
{ {
int i_submodule;
(void)p_this; (void)p_this;
p_cache->pf_activate = p_module->pf_activate; p_cache->pf_activate = p_module->pf_activate;
p_cache->pf_deactivate = p_module->pf_deactivate; p_cache->pf_deactivate = p_module->pf_deactivate;
p_cache->handle = p_module->handle; p_cache->handle = p_module->handle;
for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) /* FIXME: This looks too simplistic an algorithm to me. What if the module
* file was altered such that the number of order of submodules was
* altered... after VLC started -- Courmisch, 09/2008 */
module_t *p_child = p_module->submodule,
*p_cchild = p_cache->submodule;
while( p_child && p_cchild )
{ {
module_t *p_child = (module_t*)vlc_internals( p_module )->pp_children[i_submodule];
module_t *p_cchild = (module_t*)vlc_internals( p_cache )->pp_children[i_submodule];
p_cchild->pf_activate = p_child->pf_activate; p_cchild->pf_activate = p_child->pf_activate;
p_cchild->pf_deactivate = p_child->pf_deactivate; p_cchild->pf_deactivate = p_child->pf_deactivate;
p_child = p_child->next;
p_cchild = p_cchild->next;
} }
p_cache->b_loaded = true; p_cache->b_loaded = true;
......
...@@ -35,40 +35,78 @@ ...@@ -35,40 +35,78 @@
# define dgettext(d, m) ((char *)(m)) # define dgettext(d, m) ((char *)(m))
#endif #endif
static void vlc_module_destruct (gc_object_t *obj)
{
module_t *module = vlc_priv (obj, module_t);
vlc_mutex_destroy (&module->lock);
free (module);
}
static const char default_name[] = "unnamed"; static const char default_name[] = "unnamed";
module_t *vlc_module_create (vlc_object_t *obj) module_t *vlc_module_create (vlc_object_t *obj)
{ {
module_t *module = module_t *module = malloc (sizeof (*module));
(module_t *)vlc_custom_create (obj, sizeof (module_t),
VLC_OBJECT_MODULE, "module");
if (module == NULL) if (module == NULL)
return NULL; return NULL;
module->b_reentrant = module->b_unloadable = true;
module->psz_object_name = strdup( default_name ); module->psz_object_name = strdup( default_name );
module->next = NULL;
module->submodule = NULL;
module->parent = NULL;
module->submodule_count = 0;
vlc_gc_init (module, vlc_module_destruct);
vlc_mutex_init (&module->lock);
module->psz_shortname = NULL;
module->psz_longname = (char*)default_name; module->psz_longname = (char*)default_name;
module->psz_help = NULL;
for (unsigned i = 0; i < MODULE_SHORTCUT_MAX; i++)
module->pp_shortcuts[i] = NULL;
module->psz_capability = (char*)""; module->psz_capability = (char*)"";
module->i_score = 1; module->i_score = 1;
module->i_config_items = module->i_bool_items = 0; module->i_cpu = 0;
module->b_unloadable = true;
module->b_reentrant = true;
module->b_submodule = false;
module->pf_activate = NULL;
module->pf_deactivate = NULL;
module->p_config = NULL;
module->confsize = 0;
module->i_config_items = 0;
module->i_bool_items = 0;
/*module->handle = garbage */
module->psz_filename = NULL;
module->b_builtin = false;
module->b_loaded = false;
(void)obj;
return module; return module;
} }
static void vlc_submodule_destruct (gc_object_t *obj)
{
module_t *module = vlc_priv (obj, module_t);
free (module);
}
module_t *vlc_submodule_create (module_t *module) module_t *vlc_submodule_create (module_t *module)
{ {
assert (module != NULL); assert (module != NULL);
assert (!module->b_submodule); // subsubmodules are not supported
module_t *submodule = module_t *submodule = malloc (sizeof (*submodule));
(module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
VLC_OBJECT_MODULE, "submodule");
if (submodule == NULL) if (submodule == NULL)
return NULL; return NULL;
vlc_object_attach (submodule, module); memset (submodule, 0, sizeof (*submodule));
submodule->b_submodule = true; vlc_gc_init (submodule, vlc_submodule_destruct);
submodule->next = module->submodule;
submodule->parent = module;
module->submodule = submodule;
module->submodule_count++;
/* Muahahaha! Heritage! Polymorphism! Ugliness!! */ /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
memcpy (submodule->pp_shortcuts, module->pp_shortcuts, memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
...@@ -80,6 +118,7 @@ module_t *vlc_submodule_create (module_t *module) ...@@ -80,6 +118,7 @@ module_t *vlc_submodule_create (module_t *module)
submodule->psz_capability = module->psz_capability; submodule->psz_capability = module->psz_capability;
submodule->i_score = module->i_score; submodule->i_score = module->i_score;
submodule->i_cpu = module->i_cpu; submodule->i_cpu = module->i_cpu;
submodule->b_submodule = true;
return submodule; return submodule;
} }
...@@ -220,7 +259,7 @@ module_config_t *vlc_config_create (module_t *module, int type) ...@@ -220,7 +259,7 @@ module_config_t *vlc_config_create (module_t *module, int type)
memset (tab + confsize, 0, sizeof (tab[confsize])); memset (tab + confsize, 0, sizeof (tab[confsize]));
tab[confsize].i_type = type; tab[confsize].i_type = type;
tab[confsize].p_lock = &(vlc_internals(module)->lock); tab[confsize].p_lock = &module->lock;
if (type & CONFIG_ITEM) if (type & CONFIG_ITEM)
{ {
......
This diff is collapsed.
...@@ -56,6 +56,8 @@ struct module_bank_t ...@@ -56,6 +56,8 @@ struct module_bank_t
int i_loaded_cache; int i_loaded_cache;
module_cache_t **pp_loaded_cache; module_cache_t **pp_loaded_cache;
module_t *head;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -98,7 +100,13 @@ typedef shl_t module_handle_t; ...@@ -98,7 +100,13 @@ typedef shl_t module_handle_t;
*/ */
struct module_t struct module_t
{ {
VLC_COMMON_MEMBERS char *psz_object_name;
module_t *next;
module_t *submodule;
module_t *parent;
unsigned submodule_count;
gc_object_t vlc_gc_data;
vlc_mutex_t lock;
/* /*
* Variables set by the module to identify itself * Variables set by the module to identify itself
...@@ -141,6 +149,16 @@ struct module_t ...@@ -141,6 +149,16 @@ struct module_t
bool b_loaded; /* Set to true if the dll is loaded */ bool b_loaded; /* Set to true if the dll is loaded */
}; };
static inline module_t *module_hold (module_t *m)
{
vlc_hold (&m->vlc_gc_data);
return m;
}
static inline void module_release (module_t *m)
{
vlc_release (&m->vlc_gc_data);
}
#define module_InitBank(a) __module_InitBank(VLC_OBJECT(a)) #define module_InitBank(a) __module_InitBank(VLC_OBJECT(a))
void __module_InitBank ( vlc_object_t * ); void __module_InitBank ( vlc_object_t * );
......
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