From 54d295c247deb1f543d922eb838d3eff2f7a89ce Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 30 Dec 2017 18:00:40 +0100 Subject: MusicChunkPtr: managed MusicChunk pointer Make all uses of MusicChunk safe. --- src/decoder/Bridge.cxx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/decoder/Bridge.cxx') 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 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(); -- cgit v1.2.3