summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-02-05 13:37:20 +0100
committerMax Kellermann <max@musicpd.org>2017-02-05 13:37:20 +0100
commit43348a3e138ebcfef9551b436b52426b23176115 (patch)
tree69f7d419fabd5f937bcb6baddddf1c482da08233
parente716b1f4d7ba0c2cc5d023b019d11c1de9306f8d (diff)
decoder/Control: improve locking in Start() and Seek()
Previously, both methods accessed a lot of attributes which require mutex protection.
-rw-r--r--src/decoder/DecoderControl.cxx9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/decoder/DecoderControl.cxx b/src/decoder/DecoderControl.cxx
index 71c1c8cd1..92a21873d 100644
--- a/src/decoder/DecoderControl.cxx
+++ b/src/decoder/DecoderControl.cxx
@@ -95,6 +95,8 @@ DecoderControl::Start(DetachedSong *_song,
SongTime _start_time, SongTime _end_time,
MusicBuffer &_buffer, MusicPipe &_pipe)
{
+ const std::lock_guard<Mutex> protect(mutex);
+
assert(_song != nullptr);
assert(_pipe.IsEmpty());
@@ -105,7 +107,8 @@ DecoderControl::Start(DetachedSong *_song,
buffer = &_buffer;
pipe = &_pipe;
- LockSynchronousCommand(DecoderCommand::START);
+ ClearError();
+ SynchronousCommandLocked(DecoderCommand::START);
}
void
@@ -127,6 +130,8 @@ DecoderControl::Stop()
void
DecoderControl::Seek(SongTime t)
{
+ const std::lock_guard<Mutex> protect(mutex);
+
assert(state != DecoderState::START);
assert(state != DecoderState::ERROR);
@@ -149,7 +154,7 @@ DecoderControl::Seek(SongTime t)
seek_time = t;
seek_error = false;
- LockSynchronousCommand(DecoderCommand::SEEK);
+ SynchronousCommandLocked(DecoderCommand::SEEK);
if (seek_error)
throw std::runtime_error("Decoder failed to seek");