diff --git a/src/MusicChunk.hxx b/src/MusicChunk.hxx index 1ff93a442..25cb87358 100644 --- a/src/MusicChunk.hxx +++ b/src/MusicChunk.hxx @@ -45,7 +45,7 @@ struct MusicChunk; */ struct MusicChunkInfo { /** the next chunk in a linked list */ - MusicChunk *next; + MusicChunkPtr next; /** * An optional chunk which should be mixed into this chunk. diff --git a/src/MusicPipe.cxx b/src/MusicPipe.cxx index 6a6a66988..e60fe9434 100644 --- a/src/MusicPipe.cxx +++ b/src/MusicPipe.cxx @@ -28,7 +28,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept { const std::lock_guard protect(mutex); - for (const MusicChunk *i = head; i != nullptr; i = i->next) + for (const MusicChunk *i = head.get(); i != nullptr; i = i->next.get()) if (i == chunk) return true; @@ -42,11 +42,11 @@ MusicPipe::Shift() noexcept { const std::lock_guard protect(mutex); - MusicChunk *chunk = head; + auto chunk = std::move(head); if (chunk != nullptr) { assert(!chunk->IsEmpty()); - head = chunk->next; + head = std::move(chunk->next); --size; if (head == nullptr) { @@ -60,15 +60,12 @@ MusicPipe::Shift() noexcept } #ifndef NDEBUG - /* poison the "next" reference */ - chunk->next = (MusicChunk *)(void *)0x01010101; - if (size == 0) audio_format.Clear(); #endif } - return MusicChunkPtr(chunk, MusicChunkDeleter(buffer)); + return chunk; } void @@ -94,10 +91,9 @@ MusicPipe::Push(MusicChunkPtr chunk) noexcept audio_format = chunk->audio_format; #endif - auto *c = chunk.release(); - c->next = nullptr; - *tail_r = c; - tail_r = &c->next; + chunk->next.reset(); + *tail_r = std::move(chunk); + tail_r = &(*tail_r)->next; ++size; } diff --git a/src/MusicPipe.hxx b/src/MusicPipe.hxx index 57ae0dd7c..65e620a83 100644 --- a/src/MusicPipe.hxx +++ b/src/MusicPipe.hxx @@ -43,10 +43,10 @@ class MusicPipe { MusicBuffer &buffer; /** the first chunk */ - MusicChunk *head = nullptr; + MusicChunkPtr head; /** a pointer to the tail of the chunk */ - MusicChunk **tail_r = &head; + MusicChunkPtr *tail_r = &head; /** the current number of chunks */ unsigned size = 0; @@ -102,7 +102,7 @@ public: gcc_pure const MusicChunk *Peek() const noexcept { const std::lock_guard protect(mutex); - return head; + return head.get(); } /** diff --git a/src/output/SharedPipeConsumer.cxx b/src/output/SharedPipeConsumer.cxx index f88e242a5..e99fa0568 100644 --- a/src/output/SharedPipeConsumer.cxx +++ b/src/output/SharedPipeConsumer.cxx @@ -33,7 +33,7 @@ SharedPipeConsumer::Get() noexcept return nullptr; consumed = false; - return chunk = chunk->next; + return chunk = chunk->next.get(); } else { /* get the first chunk from the pipe */ consumed = false;