MusicChunkPtr: managed MusicChunk pointer
Make all uses of MusicChunk safe.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "Client.hxx"
|
||||
#include "ReplayGainInfo.hxx"
|
||||
#include "MusicChunkPtr.hxx"
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
@@ -89,7 +90,7 @@ public:
|
||||
std::unique_ptr<Tag> decoder_tag;
|
||||
|
||||
/** the chunk currently being written to */
|
||||
MusicChunk *current_chunk = nullptr;
|
||||
MusicChunkPtr current_chunk;
|
||||
|
||||
ReplayGainInfo replay_gain_info;
|
||||
|
||||
|
Reference in New Issue
Block a user