Music{Pipe,Chunk}: use MusicChunkPtr for the list links
This commit is contained in:
parent
88f1233d7b
commit
076be809c2
@ -45,7 +45,7 @@ struct MusicChunk;
|
|||||||
*/
|
*/
|
||||||
struct MusicChunkInfo {
|
struct MusicChunkInfo {
|
||||||
/** the next chunk in a linked list */
|
/** the next chunk in a linked list */
|
||||||
MusicChunk *next;
|
MusicChunkPtr next;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An optional chunk which should be mixed into this chunk.
|
* An optional chunk which should be mixed into this chunk.
|
||||||
|
@ -28,7 +28,7 @@ MusicPipe::Contains(const MusicChunk *chunk) const noexcept
|
|||||||
{
|
{
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
const std::lock_guard<Mutex> 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)
|
if (i == chunk)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -42,11 +42,11 @@ MusicPipe::Shift() noexcept
|
|||||||
{
|
{
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
const std::lock_guard<Mutex> protect(mutex);
|
||||||
|
|
||||||
MusicChunk *chunk = head;
|
auto chunk = std::move(head);
|
||||||
if (chunk != nullptr) {
|
if (chunk != nullptr) {
|
||||||
assert(!chunk->IsEmpty());
|
assert(!chunk->IsEmpty());
|
||||||
|
|
||||||
head = chunk->next;
|
head = std::move(chunk->next);
|
||||||
--size;
|
--size;
|
||||||
|
|
||||||
if (head == nullptr) {
|
if (head == nullptr) {
|
||||||
@ -60,15 +60,12 @@ MusicPipe::Shift() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
/* poison the "next" reference */
|
|
||||||
chunk->next = (MusicChunk *)(void *)0x01010101;
|
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
audio_format.Clear();
|
audio_format.Clear();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return MusicChunkPtr(chunk, MusicChunkDeleter(buffer));
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -94,10 +91,9 @@ MusicPipe::Push(MusicChunkPtr chunk) noexcept
|
|||||||
audio_format = chunk->audio_format;
|
audio_format = chunk->audio_format;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto *c = chunk.release();
|
chunk->next.reset();
|
||||||
c->next = nullptr;
|
*tail_r = std::move(chunk);
|
||||||
*tail_r = c;
|
tail_r = &(*tail_r)->next;
|
||||||
tail_r = &c->next;
|
|
||||||
|
|
||||||
++size;
|
++size;
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,10 @@ class MusicPipe {
|
|||||||
MusicBuffer &buffer;
|
MusicBuffer &buffer;
|
||||||
|
|
||||||
/** the first chunk */
|
/** the first chunk */
|
||||||
MusicChunk *head = nullptr;
|
MusicChunkPtr head;
|
||||||
|
|
||||||
/** a pointer to the tail of the chunk */
|
/** a pointer to the tail of the chunk */
|
||||||
MusicChunk **tail_r = &head;
|
MusicChunkPtr *tail_r = &head;
|
||||||
|
|
||||||
/** the current number of chunks */
|
/** the current number of chunks */
|
||||||
unsigned size = 0;
|
unsigned size = 0;
|
||||||
@ -102,7 +102,7 @@ public:
|
|||||||
gcc_pure
|
gcc_pure
|
||||||
const MusicChunk *Peek() const noexcept {
|
const MusicChunk *Peek() const noexcept {
|
||||||
const std::lock_guard<Mutex> protect(mutex);
|
const std::lock_guard<Mutex> protect(mutex);
|
||||||
return head;
|
return head.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,7 @@ SharedPipeConsumer::Get() noexcept
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
consumed = false;
|
consumed = false;
|
||||||
return chunk = chunk->next;
|
return chunk = chunk->next.get();
|
||||||
} else {
|
} else {
|
||||||
/* get the first chunk from the pipe */
|
/* get the first chunk from the pipe */
|
||||||
consumed = false;
|
consumed = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user