diff options
author | Max Kellermann <max@duempel.org> | 2009-11-07 15:14:16 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-11-07 15:14:16 +0100 |
commit | 5d55b45654eacd479a93673f9ec9ad3627952a96 (patch) | |
tree | 4602220efc2da432bc1aac9a828f3694064a9af5 /src/decoder_list.c | |
parent | e3da174fca30c493ec311e41ad3dc6795053757d (diff) | |
download | mpd-5d55b45654eacd479a93673f9ec9ad3627952a96.tar.gz mpd-5d55b45654eacd479a93673f9ec9ad3627952a96.tar.xz mpd-5d55b45654eacd479a93673f9ec9ad3627952a96.zip |
decoder_list: pass previous plugin pointer to lookup functions
Remove the static integer hack, that's not thread safe and sucks.
Diffstat (limited to '')
-rw-r--r-- | src/decoder_list.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/decoder_list.c b/src/decoder_list.c index 837c5ca7b..53c882161 100644 --- a/src/decoder_list.c +++ b/src/decoder_list.c @@ -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; |