diff options
author | Max Kellermann <max@musicpd.org> | 2017-12-30 18:00:40 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-06-22 23:11:52 +0200 |
commit | 54d295c247deb1f543d922eb838d3eff2f7a89ce (patch) | |
tree | 1f97982f7a1feb5e70a9ff4cc29d0c08e197cf0c /src/decoder/Bridge.cxx | |
parent | e81b089612833b61c566b482640615e182949ac6 (diff) |
MusicChunkPtr: managed MusicChunk pointer
Make all uses of MusicChunk safe.
Diffstat (limited to 'src/decoder/Bridge.cxx')
-rw-r--r-- | src/decoder/Bridge.cxx | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/decoder/Bridge.cxx b/src/decoder/Bridge.cxx index 87d2e3a8a..c8ae799b9 100644 --- a/src/decoder/Bridge.cxx +++ b/src/decoder/Bridge.cxx @@ -95,7 +95,7 @@ DecoderBridge::GetChunk() noexcept DecoderCommand cmd; if (current_chunk != nullptr) - return current_chunk; + return current_chunk.get(); do { current_chunk = dc.pipe->GetBuffer().Allocate(); @@ -104,7 +104,7 @@ DecoderBridge::GetChunk() noexcept if (replay_gain_serial != 0) current_chunk->replay_gain_info = replay_gain_info; - return current_chunk; + return current_chunk.get(); } cmd = LockNeedChunks(dc); @@ -121,11 +121,9 @@ DecoderBridge::FlushChunk() assert(!initial_seek_pending); assert(current_chunk != nullptr); - auto *chunk = std::exchange(current_chunk, nullptr); - if (chunk->IsEmpty()) - dc.pipe->GetBuffer().Return(chunk); - else - dc.pipe->Push(chunk); + auto chunk = std::move(current_chunk); + if (!chunk->IsEmpty()) + dc.pipe->Push(std::move(chunk)); const std::lock_guard<Mutex> protect(dc.mutex); if (dc.client_is_waiting) @@ -302,10 +300,7 @@ DecoderBridge::CommandFinished() /* delete frames from the old song position */ - if (current_chunk != nullptr) { - dc.pipe->GetBuffer().Return(current_chunk); - current_chunk = nullptr; - } + current_chunk.reset(); dc.pipe->Clear(); |