diff options
author | David Robillard <d@drobilla.net> | 2018-01-21 14:28:34 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-01-21 14:29:15 +0100 |
commit | ac778d258e0866d1117aadf576de2ff89df3e84d (patch) | |
tree | 1670fc3a66ec9a4493264421b27e845ef0d65b3d /src/server/Buffer.cpp | |
parent | 95e74234a923dcd7bd7c43f76919c61cf46b4e69 (diff) | |
download | ingen-ac778d258e0866d1117aadf576de2ff89df3e84d.tar.gz ingen-ac778d258e0866d1117aadf576de2ff89df3e84d.tar.bz2 ingen-ac778d258e0866d1117aadf576de2ff89df3e84d.zip |
Clean up Buffer class and factor out allocation
Diffstat (limited to 'src/server/Buffer.cpp')
-rw-r--r-- | src/server/Buffer.cpp | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/server/Buffer.cpp b/src/server/Buffer.cpp index d609a2af..1952beb2 100644 --- a/src/server/Buffer.cpp +++ b/src/server/Buffer.cpp @@ -47,30 +47,18 @@ Buffer::Buffer(BufferFactory& bufs, bool external, void* buf) : _factory(bufs) - , _buf(nullptr) + , _next(nullptr) + , _buf(external ? nullptr : aligned_alloc(capacity)) + , _latest_event(0) , _type(type) , _value_type(value_type) , _capacity(capacity) - , _latest_event(0) - , _next(nullptr) , _refs(0) , _external(external) { - if (!external) { -#ifdef HAVE_POSIX_MEMALIGN - int ret = posix_memalign((void**)&_buf, 16, capacity); - if (!ret) { - memset(_buf, 0, capacity); - } -#else - _buf = (LV2_buf*)calloc(1, capacity); - int ret = (_buf != NULL) ? 0 : -1; -#endif - - if (ret) { - bufs.engine().log().rt_error("Failed to allocate event buffer\n"); - throw std::bad_alloc(); - } + if (!external && !_buf) { + bufs.engine().log().rt_error("Failed to allocate buffer\n"); + throw std::bad_alloc(); } if (type != bufs.uris().atom_Sound) { @@ -450,6 +438,20 @@ Buffer::dump_cv(const RunContext& context) const } #endif +void* Buffer::aligned_alloc(size_t size) +{ +#ifdef HAVE_POSIX_MEMALIGN + void* buf; + if (!posix_memalign((void**)&buf, 16, size)) { + memset(buf, 0, size); + return buf; + } +#else + return (LV2_buf*)calloc(1, size); +#endif + return nullptr; +} + void intrusive_ptr_add_ref(Buffer* b) { |