mirror of
https://github.com/matrix-construct/construct
synced 2024-12-02 03:32:52 +01:00
ircd::allocator: Meet posix spec requirements for posix_memalign().
This commit is contained in:
parent
51b3e63959
commit
91bed23951
1 changed files with 16 additions and 7 deletions
|
@ -475,18 +475,27 @@ ircd::allocator::operator+=(profile &a,
|
||||||
//
|
//
|
||||||
|
|
||||||
std::unique_ptr<char, decltype(&std::free)>
|
std::unique_ptr<char, decltype(&std::free)>
|
||||||
ircd::allocator::aligned_alloc(const size_t &align,
|
ircd::allocator::aligned_alloc(const size_t &alignment_,
|
||||||
const size_t &size)
|
const size_t &size_)
|
||||||
{
|
{
|
||||||
static const size_t &align_default{16};
|
static const size_t &align_default
|
||||||
const size_t &alignment
|
|
||||||
{
|
{
|
||||||
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 % alignment == 0);
|
||||||
|
assert(size < size_ + alignment);
|
||||||
|
assert(alignment % sizeof(void *) == 0);
|
||||||
|
|
||||||
void *ret;
|
void *ret;
|
||||||
switch(int errc(::posix_memalign(&ret, alignment, size)); errc)
|
switch(int errc(::posix_memalign(&ret, alignment, size)); errc)
|
||||||
|
|
Loading…
Reference in a new issue