mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd::buffer: Support aligned allocations and aligned unique_buffer conversion.
This commit is contained in:
parent
7e3b5db06a
commit
062ea9ddf5
1 changed files with 35 additions and 12 deletions
|
@ -18,16 +18,26 @@ struct ircd::buffer::shared_buffer
|
|||
:std::shared_ptr<char>
|
||||
,buffer
|
||||
{
|
||||
shared_buffer(const size_t &size);
|
||||
shared_buffer(unique_buffer<buffer> &&);
|
||||
shared_buffer();
|
||||
explicit shared_buffer(const size_t &size, const size_t &align = 0);
|
||||
shared_buffer(unique_buffer<buffer> &&) noexcept;
|
||||
explicit shared_buffer(const const_buffer &);
|
||||
shared_buffer() = default;
|
||||
shared_buffer(shared_buffer &&) = default;
|
||||
shared_buffer(const shared_buffer &) = default;
|
||||
shared_buffer &operator=(shared_buffer &&) = default;
|
||||
shared_buffer &operator=(const shared_buffer &) = default;
|
||||
shared_buffer &operator=(unique_buffer<buffer> &&) noexcept;
|
||||
~shared_buffer() = default;
|
||||
};
|
||||
|
||||
template<class buffer>
|
||||
ircd::buffer::shared_buffer<buffer>::shared_buffer()
|
||||
:std::shared_ptr<char>
|
||||
{
|
||||
nullptr, std::free
|
||||
}
|
||||
{}
|
||||
|
||||
template<class buffer>
|
||||
ircd::buffer::shared_buffer<buffer>::shared_buffer(const const_buffer &src)
|
||||
:shared_buffer
|
||||
|
@ -42,30 +52,43 @@ ircd::buffer::shared_buffer<buffer>::shared_buffer(const const_buffer &src)
|
|||
|
||||
template<class buffer>
|
||||
ircd::buffer::shared_buffer<buffer>::shared_buffer(unique_buffer<buffer> &&buf)
|
||||
noexcept
|
||||
:std::shared_ptr<char>
|
||||
{
|
||||
data(buf),
|
||||
std::default_delete<char[]>()
|
||||
data(buf), std::free
|
||||
}
|
||||
,buffer
|
||||
{
|
||||
this->std::shared_ptr<char>::get(),
|
||||
size(buf)
|
||||
this->std::shared_ptr<char>::get(), size(buf)
|
||||
}
|
||||
{
|
||||
buf.release();
|
||||
}
|
||||
|
||||
template<class buffer>
|
||||
ircd::buffer::shared_buffer<buffer>::shared_buffer(const size_t &size)
|
||||
ircd::buffer::shared_buffer<buffer>::shared_buffer(const size_t &size,
|
||||
const size_t &align)
|
||||
:std::shared_ptr<char>
|
||||
{
|
||||
new __attribute__((aligned(16))) char[size],
|
||||
std::default_delete<char[]>()
|
||||
allocator::aligned_alloc(align, size).release(), std::free
|
||||
}
|
||||
,buffer
|
||||
{
|
||||
this->std::shared_ptr<char>::get(),
|
||||
size
|
||||
this->std::shared_ptr<char>::get(), size
|
||||
}
|
||||
{}
|
||||
|
||||
template<class buffer>
|
||||
ircd::buffer::shared_buffer<buffer> &
|
||||
ircd::buffer::shared_buffer<buffer>::operator=(unique_buffer<buffer> &&buf)
|
||||
noexcept
|
||||
{
|
||||
this->std::shared_ptr<char>::reset(data(buf), std::free);
|
||||
*static_cast<buffer *>(this) =
|
||||
{
|
||||
this->std::shared_ptr<char>::get(), size(buf)
|
||||
};
|
||||
|
||||
buf.release();
|
||||
return *this;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue