Commit 43348a3e authored by Max Kellermann's avatar Max Kellermann

decoder/Control: improve locking in Start() and Seek()

Previously, both methods accessed a lot of attributes which require mutex protection.
parent e716b1f4
...@@ -95,6 +95,8 @@ DecoderControl::Start(DetachedSong *_song, ...@@ -95,6 +95,8 @@ DecoderControl::Start(DetachedSong *_song,
SongTime _start_time, SongTime _end_time, SongTime _start_time, SongTime _end_time,
MusicBuffer &_buffer, MusicPipe &_pipe) MusicBuffer &_buffer, MusicPipe &_pipe)
{ {
const std::lock_guard<Mutex> protect(mutex);
assert(_song != nullptr); assert(_song != nullptr);
assert(_pipe.IsEmpty()); assert(_pipe.IsEmpty());
...@@ -105,7 +107,8 @@ DecoderControl::Start(DetachedSong *_song, ...@@ -105,7 +107,8 @@ DecoderControl::Start(DetachedSong *_song,
buffer = &_buffer; buffer = &_buffer;
pipe = &_pipe; pipe = &_pipe;
LockSynchronousCommand(DecoderCommand::START); ClearError();
SynchronousCommandLocked(DecoderCommand::START);
} }
void void
...@@ -127,6 +130,8 @@ DecoderControl::Stop() ...@@ -127,6 +130,8 @@ DecoderControl::Stop()
void void
DecoderControl::Seek(SongTime t) DecoderControl::Seek(SongTime t)
{ {
const std::lock_guard<Mutex> protect(mutex);
assert(state != DecoderState::START); assert(state != DecoderState::START);
assert(state != DecoderState::ERROR); assert(state != DecoderState::ERROR);
...@@ -149,7 +154,7 @@ DecoderControl::Seek(SongTime t) ...@@ -149,7 +154,7 @@ DecoderControl::Seek(SongTime t)
seek_time = t; seek_time = t;
seek_error = false; seek_error = false;
LockSynchronousCommand(DecoderCommand::SEEK); SynchronousCommandLocked(DecoderCommand::SEEK);
if (seek_error) if (seek_error)
throw std::runtime_error("Decoder failed to seek"); throw std::runtime_error("Decoder failed to seek");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment