Alloc: Use posix_memalign() instead of aligned_alloc()
For compatibility with older systems use posix_memalign(). We can switch to aligned_alloc() when we commit to C11 for multithreading.
This commit is contained in:
parent
ef614f2984
commit
2fc8b4c4ba
1 changed files with 6 additions and 5 deletions
|
@ -72,16 +72,17 @@ alloc_page(void)
|
||||||
{
|
{
|
||||||
void *ret = mmap(NULL, get_page_size(), PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
void *ret = mmap(NULL, get_page_size(), PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
if (ret == MAP_FAILED)
|
if (ret == MAP_FAILED)
|
||||||
bug("mmap(%lu) failed: %m", page_size);
|
bug("mmap(%lu) failed: %m", (long unsigned int) page_size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
void *ret = aligned_alloc(page_size, page_size);
|
void *ptr = NULL;
|
||||||
if (!ret)
|
int err = posix_memalign(&ptr, page_size, page_size);
|
||||||
bug("aligned_alloc(%lu) failed", page_size);
|
if (err || !ptr)
|
||||||
return ret;
|
bug("posix_memalign(%lu) failed", (long unsigned int) page_size);
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue