MusicChunkPtr: managed MusicChunk pointer
Make all uses of MusicChunk safe.
This commit is contained in:
@@ -27,11 +27,11 @@ MusicBuffer::MusicBuffer(unsigned num_chunks) noexcept
|
||||
:buffer(num_chunks) {
|
||||
}
|
||||
|
||||
MusicChunk *
|
||||
MusicChunkPtr
|
||||
MusicBuffer::Allocate() noexcept
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
return buffer.Allocate();
|
||||
return MusicChunkPtr(buffer.Allocate(), MusicChunkDeleter(*this));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -41,10 +41,7 @@ MusicBuffer::Return(MusicChunk *chunk) noexcept
|
||||
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
|
||||
if (chunk->other != nullptr) {
|
||||
assert(chunk->other->other == nullptr);
|
||||
buffer.Free(chunk->other);
|
||||
}
|
||||
assert(!chunk->other || !chunk->other->other);
|
||||
|
||||
buffer.Free(chunk);
|
||||
}
|
||||
|
Reference in New Issue
Block a user