0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd::buffer: Add unique to shared buffer conversion.

This commit is contained in:
Jason Volk 2019-08-31 21:52:54 -07:00
parent a9984d8b7a
commit 7e3b5db06a

View file

@ -19,6 +19,7 @@ struct ircd::buffer::shared_buffer
,buffer ,buffer
{ {
shared_buffer(const size_t &size); shared_buffer(const size_t &size);
shared_buffer(unique_buffer<buffer> &&);
explicit shared_buffer(const const_buffer &); explicit shared_buffer(const const_buffer &);
shared_buffer() = default; shared_buffer() = default;
shared_buffer(shared_buffer &&) = default; shared_buffer(shared_buffer &&) = default;
@ -27,19 +28,6 @@ struct ircd::buffer::shared_buffer
shared_buffer &operator=(const 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>
{
new __attribute__((aligned(16))) char[size],
std::default_delete<char[]>()
}
,buffer
{
this->std::shared_ptr<char>::get(), size
}
{}
template<class buffer> template<class buffer>
ircd::buffer::shared_buffer<buffer>::shared_buffer(const const_buffer &src) ircd::buffer::shared_buffer<buffer>::shared_buffer(const const_buffer &src)
:shared_buffer :shared_buffer
@ -51,3 +39,33 @@ ircd::buffer::shared_buffer<buffer>::shared_buffer(const const_buffer &src)
assert(size(dst) == size(src)); assert(size(dst) == size(src));
copy(dst, src); copy(dst, src);
} }
template<class buffer>
ircd::buffer::shared_buffer<buffer>::shared_buffer(unique_buffer<buffer> &&buf)
:std::shared_ptr<char>
{
data(buf),
std::default_delete<char[]>()
}
,buffer
{
this->std::shared_ptr<char>::get(),
size(buf)
}
{
buf.release();
}
template<class buffer>
ircd::buffer::shared_buffer<buffer>::shared_buffer(const size_t &size)
:std::shared_ptr<char>
{
new __attribute__((aligned(16))) char[size],
std::default_delete<char[]>()
}
,buffer
{
this->std::shared_ptr<char>::get(),
size
}
{}