decoder_list: pass previous plugin pointer to lookup functions

Remove the static integer hack, that's not thread safe and sucks.
This commit is contained in:
Max Kellermann
2009-11-07 15:14:16 +01:00
parent e3da174fca
commit 5d55b45654
4 changed files with 40 additions and 19 deletions

View File

@@ -107,23 +107,38 @@ enum {
/** which plugins have been initialized successfully? */
static bool decoder_plugins_enabled[num_decoder_plugins];
const struct decoder_plugin *
decoder_plugin_from_suffix(const char *suffix, unsigned int next)
static unsigned
decoder_plugin_index(const struct decoder_plugin *plugin)
{
static unsigned i = num_decoder_plugins;
unsigned i = 0;
while (decoder_plugins[i] != plugin)
++i;
return i;
}
static unsigned
decoder_plugin_next_index(const struct decoder_plugin *plugin)
{
return plugin == 0
? 0 /* start with first plugin */
: decoder_plugin_index(plugin) + 1;
}
const struct decoder_plugin *
decoder_plugin_from_suffix(const char *suffix,
const struct decoder_plugin *plugin)
{
if (suffix == NULL)
return NULL;
if (!next)
i = 0;
for (; decoder_plugins[i] != NULL; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i];
for (unsigned i = decoder_plugin_next_index(plugin);
decoder_plugins[i] != NULL; ++i) {
plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
decoder_plugin_supports_suffix(plugin, suffix)) {
++i;
decoder_plugin_supports_suffix(plugin, suffix))
return plugin;
}
}
return NULL;