diff options
author | Max Kellermann <max@duempel.org> | 2013-09-26 22:09:42 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-09-26 22:21:56 +0200 |
commit | 3216f4b25753d566793173c7a4f53a126ac37744 (patch) | |
tree | 5a151a5c6f1750011279b50f0c8478787dac46e8 /src/MusicBuffer.cxx | |
parent | ce1d8975751251d49581129193e09490ca650a8b (diff) | |
download | mpd-3216f4b25753d566793173c7a4f53a126ac37744.tar.gz mpd-3216f4b25753d566793173c7a4f53a126ac37744.tar.xz mpd-3216f4b25753d566793173c7a4f53a126ac37744.zip |
MusicBuffer: expose the C++ API
Diffstat (limited to '')
-rw-r--r-- | src/MusicBuffer.cxx | 52 |
1 files changed, 13 insertions, 39 deletions
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 <assert.h> -struct music_buffer : public SliceBuffer<music_chunk> { - /** 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); } |