Move common macros into bionic_macros.h.

Bug: 15590152
Change-Id: I730636613ef3653f68c5ab1d43b53beaf8e0dc25
This commit is contained in:
Christopher Ferris
2014-06-13 13:57:51 -07:00
parent 64dfbd242c
commit 03eebcb6e8
8 changed files with 42 additions and 29 deletions

View File

@@ -14,13 +14,19 @@
* limitations under the License.
*/
#include <sys/param.h>
#include <unistd.h>
#include "jemalloc.h"
#include "private/bionic_macros.h"
void* je_pvalloc(size_t bytes) {
size_t pagesize = sysconf(_SC_PAGESIZE);
return je_memalign(pagesize, (bytes + pagesize - 1) & ~(pagesize - 1));
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) {
return NULL;
}
return je_memalign(pagesize, size);
}
#ifdef je_memalign
@@ -31,11 +37,9 @@ void* je_pvalloc(size_t bytes) {
// but this is not true. Both glibc and dlmalloc round up to the next power
// of 2, so we'll do the same.
void* je_memalign_round_up_boundary(size_t boundary, size_t size) {
unsigned int power_of_2 = static_cast<unsigned int>(boundary);
if (power_of_2 != 0) {
power_of_2 = 1UL << (sizeof(unsigned int)*8 - 1 - __builtin_clz(power_of_2));
if (power_of_2 != boundary) {
boundary = power_of_2 << 1;
if (boundary != 0) {
if (!powerof2(boundary)) {
boundary = BIONIC_ROUND_UP_POWER_OF_2(boundary);
}
} else {
boundary = 1;