diff options
author | Max Kellermann <max@duempel.org> | 2015-12-30 06:16:30 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-12-31 12:59:06 +0100 |
commit | 7e0cdbe502f4f05fccf773ff3d1782c905a3ad27 (patch) | |
tree | 1cd4c219a15646a8cfc529734f6d8ee8afc17e13 | |
parent | ca08902d715291e915443c6b1b0bba082283f9db (diff) |
decoder/Thread: use ScopeUnlock for exception-safety
-rw-r--r-- | src/decoder/DecoderThread.cxx | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx index 3bed1339c..394ad5ecb 100644 --- a/src/decoder/DecoderThread.cxx +++ b/src/decoder/DecoderThread.cxx @@ -144,15 +144,15 @@ decoder_stream_decode(const DecoderPlugin &plugin, /* rewind the stream, so each plugin gets a fresh start */ input_stream.Rewind(IgnoreError()); - decoder.dc.Unlock(); + { + const ScopeUnlock unlock(decoder.dc.mutex); - FormatThreadName("decoder:%s", plugin.name); + FormatThreadName("decoder:%s", plugin.name); - plugin.StreamDecode(decoder, input_stream); + plugin.StreamDecode(decoder, input_stream); - SetThreadName("decoder"); - - decoder.dc.Lock(); + SetThreadName("decoder"); + } assert(decoder.dc.state == DecoderState::START || decoder.dc.state == DecoderState::DECODE); @@ -181,15 +181,15 @@ decoder_file_decode(const DecoderPlugin &plugin, if (decoder.dc.command == DecoderCommand::STOP) return true; - decoder.dc.Unlock(); + { + const ScopeUnlock unlock(decoder.dc.mutex); - FormatThreadName("decoder:%s", plugin.name); + FormatThreadName("decoder:%s", plugin.name); - plugin.FileDecode(decoder, path); - - SetThreadName("decoder"); + plugin.FileDecode(decoder, path); - decoder.dc.Lock(); + SetThreadName("decoder"); + } assert(decoder.dc.state == DecoderState::START || decoder.dc.state == DecoderState::DECODE); @@ -389,18 +389,19 @@ decoder_run_song(DecoderControl &dc, decoder_command_finished_locked(dc); - dc.Unlock(); - - const int ret = !path_fs.IsNull() - ? decoder_run_file(decoder, uri, path_fs) - : decoder_run_stream(decoder, uri); + int ret; + { + const ScopeUnlock unlock(dc.mutex); - /* flush the last chunk */ + ret = !path_fs.IsNull() + ? decoder_run_file(decoder, uri, path_fs) + : decoder_run_stream(decoder, uri); - if (decoder.chunk != nullptr) - decoder.FlushChunk(); + /* flush the last chunk */ - dc.Lock(); + if (decoder.chunk != nullptr) + decoder.FlushChunk(); + } if (decoder.error.IsDefined()) { /* copy the Error from sruct Decoder to |