From fad0e834d5f4ef99a1971eca4db53ef6f346fed0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 31 Dec 2015 12:47:56 +0100 Subject: [PATCH] decoder/Thread: always unlock mutex before returning from TryDecoderFile() Remove that surprising rule. --- src/decoder/DecoderThread.cxx | 38 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx index 90576bc9c..616042282 100644 --- a/src/decoder/DecoderThread.cxx +++ b/src/decoder/DecoderThread.cxx @@ -312,8 +312,7 @@ decoder_load_replay_gain(Decoder &decoder, Path path_fs) /** * Decode a file with the given decoder plugin. * - * DecoderControl::mutex must not be locked by the caller. It will be - * left locked upon returning true. + * DecoderControl::mutex is not locked by caller. */ static bool TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix, @@ -327,10 +326,11 @@ TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix, if (plugin.file_decode != nullptr) { dc.Lock(); - if (decoder_file_decode(plugin, decoder, path_fs)) - return true; + bool success = decoder_file_decode(plugin, decoder, path_fs); dc.Unlock(); + + return success; } else if (plugin.stream_decode != nullptr) { InputStream *input_stream = decoder_input_stream_open(dc, path_fs); @@ -346,13 +346,9 @@ TryDecoderFile(Decoder &decoder, Path path_fs, const char *suffix, delete input_stream; - if (success) { - dc.Lock(); - return true; - } - } - - return false; + return success; + } else + return false; } /** @@ -367,21 +363,15 @@ decoder_run_file(Decoder &decoder, const char *uri_utf8, Path path_fs) if (suffix == nullptr) return false; - DecoderControl &dc = decoder.dc; - decoder_load_replay_gain(decoder, path_fs); - if (decoder_plugins_try([&decoder, path_fs, - suffix](const DecoderPlugin &plugin){ - return TryDecoderFile(decoder, - path_fs, suffix, - plugin); - })) { - dc.Unlock(); - return true; - } - - return false; + return decoder_plugins_try([&decoder, path_fs, + suffix](const DecoderPlugin &plugin){ + return TryDecoderFile(decoder, + path_fs, + suffix, + plugin); + }); } /**