0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 18:22:50 +01:00

ircd::allocator: Meet posix spec requirements for posix_memalign().

This commit is contained in:
Jason Volk 2019-04-18 00:43:44 -07:00
parent 51b3e63959
commit 91bed23951

View file

@ -475,18 +475,27 @@ ircd::allocator::operator+=(profile &a,
//
std::unique_ptr<char, decltype(&std::free)>
ircd::allocator::aligned_alloc(const size_t &align,
const size_t &size)
ircd::allocator::aligned_alloc(const size_t &alignment_,
const size_t &size_)
{
static const size_t &align_default{16};
const size_t &alignment
static const size_t &align_default
{
align?: align_default
16
};
const size_t &alignment
{
alignment_?: align_default
};
const size_t &size
{
size_ % alignment == 0? size_: size_ + (alignment - (size_ % alignment))
};
assert(alignment % 2UL == 0);
assert(alignment % sizeof(void *) == 0);
assert(size % alignment == 0);
assert(size < size_ + alignment);
assert(alignment % sizeof(void *) == 0);
void *ret;
switch(int errc(::posix_memalign(&ret, alignment, size)); errc)