0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

ircd::buffer: Make shared_buffer work.

This commit is contained in:
Jason Volk 2018-10-04 15:37:03 -07:00
parent 0e5f8141c3
commit efd8a8c640

View file

@ -11,23 +11,43 @@
#pragma once
#define HAVE_IRCD_BUFFER_SHARED_BUFFER_H
/// Like shared_ptr, this template shares ownership of an allocated buffer
///
template<class buffer>
struct ircd::buffer::shared_buffer
:std::shared_ptr<char>
,buffer
{
shared_buffer(const size_t &size);
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;
};
template<class buffer>
ircd::buffer::shared_buffer<buffer>::shared_buffer(const size_t &size)
:std::shared_ptr<char>
{
std::make_shared<char>(size)
new __attribute__((aligned(16))) char[size],
std::default_delete<char[]>()
}
,buffer
{
std::shared_ptr<char>::get(), size
this->std::shared_ptr<char>::get(), size
}
{}
template<class buffer>
ircd::buffer::shared_buffer<buffer>::shared_buffer(const const_buffer &src)
:shared_buffer
{
size(src)
}
{
const mutable_buffer dst{data(*this), size(*this)};
assert(size(dst) == size(src));
copy(dst, src);
}