decoder/Thread: use ScopeUnlock for exception-safety

This commit is contained in:
Max Kellermann 2015-12-30 06:16:30 +01:00
parent ca08902d71
commit 7e0cdbe502

View File

@ -144,15 +144,15 @@ decoder_stream_decode(const DecoderPlugin &plugin,
/* rewind the stream, so each plugin gets a fresh start */ /* rewind the stream, so each plugin gets a fresh start */
input_stream.Rewind(IgnoreError()); 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"); SetThreadName("decoder");
}
decoder.dc.Lock();
assert(decoder.dc.state == DecoderState::START || assert(decoder.dc.state == DecoderState::START ||
decoder.dc.state == DecoderState::DECODE); decoder.dc.state == DecoderState::DECODE);
@ -181,15 +181,15 @@ decoder_file_decode(const DecoderPlugin &plugin,
if (decoder.dc.command == DecoderCommand::STOP) if (decoder.dc.command == DecoderCommand::STOP)
return true; 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); plugin.FileDecode(decoder, path);
SetThreadName("decoder"); SetThreadName("decoder");
}
decoder.dc.Lock();
assert(decoder.dc.state == DecoderState::START || assert(decoder.dc.state == DecoderState::START ||
decoder.dc.state == DecoderState::DECODE); decoder.dc.state == DecoderState::DECODE);
@ -389,9 +389,11 @@ decoder_run_song(DecoderControl &dc,
decoder_command_finished_locked(dc); decoder_command_finished_locked(dc);
dc.Unlock(); int ret;
{
const ScopeUnlock unlock(dc.mutex);
const int ret = !path_fs.IsNull() ret = !path_fs.IsNull()
? decoder_run_file(decoder, uri, path_fs) ? decoder_run_file(decoder, uri, path_fs)
: decoder_run_stream(decoder, uri); : decoder_run_stream(decoder, uri);
@ -399,8 +401,7 @@ decoder_run_song(DecoderControl &dc,
if (decoder.chunk != nullptr) if (decoder.chunk != nullptr)
decoder.FlushChunk(); decoder.FlushChunk();
}
dc.Lock();
if (decoder.error.IsDefined()) { if (decoder.error.IsDefined()) {
/* copy the Error from sruct Decoder to /* copy the Error from sruct Decoder to