Skip to content
Snippets Groups Projects
Commit 0366eecd authored by Lyndon Brown's avatar Lyndon Brown Committed by Jean-Baptiste Kempf
Browse files

plugins: capture total module count

...in the modules data structure.

we thus know the precise count of modules up front in places where we want
to know this, avoiding having to process the plugins array to build a count
each time.

 - we thus can improve the efficiency of `module_list_get()`, as done.
 - we thus can simply print the count at the end of `module_LoadPlugins()`
   rather than it having to use a `module_list_get()` call to get that info.
parent a6256d3f
No related branches found
No related tags found
1 merge request!318plugins: capture total module count
Pipeline #115469 passed with stage
in 17 minutes
......@@ -96,8 +96,9 @@ static struct
vlc_mutex_t lock;
block_t *caches;
void *caps_tree;
size_t count;
unsigned usage;
} modules = { VLC_STATIC_MUTEX, NULL, NULL, 0 };
} modules = { VLC_STATIC_MUTEX, NULL, NULL, 0, 0 };
vlc_plugin_t *vlc_plugins = NULL;
......@@ -150,6 +151,7 @@ static void vlc_plugin_store(vlc_plugin_t *lib)
lib->next = vlc_plugins;
vlc_plugins = lib;
modules.count += lib->modules_count;
for (module_t *m = lib->module; m != NULL; m = m->next)
vlc_module_store(m);
......@@ -763,6 +765,7 @@ void module_EndBank (bool b_plugins)
vlc_plugins = NULL;
modules.caches = NULL;
modules.caps_tree = NULL;
modules.count = 0;
}
vlc_mutex_unlock (&modules.lock);
......@@ -805,10 +808,7 @@ void module_LoadPlugins(vlc_object_t *obj)
}
vlc_mutex_unlock (&modules.lock);
size_t count;
module_t **list = module_list_get (&count);
module_list_free (list);
msg_Dbg (obj, "plug-ins loaded: %zu modules", count);
msg_Dbg (obj, "plug-ins loaded: %zu modules", modules.count);
}
void module_list_free (module_t **list)
......@@ -818,26 +818,25 @@ void module_list_free (module_t **list)
module_t **module_list_get (size_t *n)
{
module_t **tab = NULL;
size_t i = 0;
assert (n != NULL);
*n = modules.count;
if (unlikely(modules.count == 0))
return NULL;
module_t **tab = malloc(modules.count * sizeof(*tab));
if (unlikely(tab == NULL))
return NULL;
size_t i = 0;
for (vlc_plugin_t *lib = vlc_plugins; lib != NULL; lib = lib->next)
{
module_t **nt = realloc(tab, (i + lib->modules_count) * sizeof (*tab));
if (unlikely(nt == NULL))
{
free (tab);
*n = 0;
return NULL;
}
tab = nt;
for (module_t *m = lib->module; m != NULL; m = m->next)
{
assert(i < modules.count);
tab[i++] = m;
}
}
*n = i;
return tab;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment