From 3216f4b25753d566793173c7a4f53a126ac37744 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 26 Sep 2013 22:09:42 +0200 Subject: MusicBuffer: expose the C++ API --- src/MusicBuffer.cxx | 52 +++++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) (limited to 'src/MusicBuffer.cxx') diff --git a/src/MusicBuffer.cxx b/src/MusicBuffer.cxx index eb42a0311..c811d8627 100644 --- a/src/MusicBuffer.cxx +++ b/src/MusicBuffer.cxx @@ -20,60 +20,34 @@ #include "config.h" #include "MusicBuffer.hxx" #include "MusicChunk.hxx" -#include "thread/Mutex.hxx" -#include "util/SliceBuffer.hxx" #include "system/FatalError.hxx" #include -struct music_buffer : public SliceBuffer { - /** a mutex which protects #available */ - Mutex mutex; - - music_buffer(unsigned num_chunks) - :SliceBuffer(num_chunks) { - if (IsOOM()) - FatalError("Failed to allocate buffer"); - } -}; - -struct music_buffer * -music_buffer_new(unsigned num_chunks) -{ - return new music_buffer(num_chunks); -} - -void -music_buffer_free(struct music_buffer *buffer) -{ - delete buffer; -} - -unsigned -music_buffer_size(const struct music_buffer *buffer) -{ - return buffer->GetCapacity(); +MusicBuffer::MusicBuffer(unsigned num_chunks) + :buffer(num_chunks) { + if (buffer.IsOOM()) + FatalError("Failed to allocate buffer"); } -struct music_chunk * -music_buffer_allocate(struct music_buffer *buffer) +music_chunk * +MusicBuffer::Allocate() { - const ScopeLock protect(buffer->mutex); - return buffer->Allocate(); + const ScopeLock protect(mutex); + return buffer.Allocate(); } void -music_buffer_return(struct music_buffer *buffer, struct music_chunk *chunk) +MusicBuffer::Return(music_chunk *chunk) { - assert(buffer != NULL); - assert(chunk != NULL); + assert(chunk != nullptr); - const ScopeLock protect(buffer->mutex); + const ScopeLock protect(mutex); if (chunk->other != nullptr) { assert(chunk->other->other == nullptr); - buffer->Free(chunk->other); + buffer.Free(chunk->other); } - buffer->Free(chunk); + buffer.Free(chunk); } -- cgit v1.2.3