MusicChunkPtr: managed MusicChunk pointer

Make all uses of MusicChunk safe.
This commit is contained in:
Max Kellermann
2017-12-30 18:00:40 +01:00
parent e81b089612
commit 54d295c247
14 changed files with 120 additions and 60 deletions

View File

@@ -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);
}