util/macros: Import ALIGN_POT from ralloc.c
v2 (Jason Ekstrand): - Rename y to pot_align (Brian) - Also use ALIGN_POT in build_id.c and slab.c (Brian) Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "build_id.h"
|
#include "build_id.h"
|
||||||
|
#include "macros.h"
|
||||||
|
|
||||||
#ifndef NT_GNU_BUILD_ID
|
#ifndef NT_GNU_BUILD_ID
|
||||||
#define NT_GNU_BUILD_ID 3
|
#define NT_GNU_BUILD_ID 3
|
||||||
@@ -37,8 +38,6 @@
|
|||||||
#define ElfW(type) Elf_##type
|
#define ElfW(type) Elf_##type
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
|
|
||||||
|
|
||||||
struct build_id_note {
|
struct build_id_note {
|
||||||
ElfW(Nhdr) nhdr;
|
ElfW(Nhdr) nhdr;
|
||||||
|
|
||||||
@@ -90,8 +89,8 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t offset = sizeof(ElfW(Nhdr)) +
|
size_t offset = sizeof(ElfW(Nhdr)) +
|
||||||
ALIGN(note->nhdr.n_namesz, 4) +
|
ALIGN_POT(note->nhdr.n_namesz, 4) +
|
||||||
ALIGN(note->nhdr.n_descsz, 4);
|
ALIGN_POT(note->nhdr.n_descsz, 4);
|
||||||
note = (struct build_id_note *)((char *)note + offset);
|
note = (struct build_id_note *)((char *)note + offset);
|
||||||
len -= offset;
|
len -= offset;
|
||||||
}
|
}
|
||||||
|
@@ -285,6 +285,9 @@ do { \
|
|||||||
#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
|
#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
|
||||||
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
|
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
|
||||||
|
|
||||||
|
/** Align a value to a power of two */
|
||||||
|
#define ALIGN_POT(x, pot_align) (((x) + (pot_align) - 1) & ~((pot_align) - 1))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Macro for declaring an explicit conversion operator. Defaults to an
|
* Macro for declaring an explicit conversion operator. Defaults to an
|
||||||
* implicit conversion if C++11 is not supported.
|
* implicit conversion if C++11 is not supported.
|
||||||
|
@@ -553,8 +553,6 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
|
|||||||
* other buffers.
|
* other buffers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define ALIGN_POT(x, y) (((x) + (y) - 1) & ~((y) - 1))
|
|
||||||
|
|
||||||
#define MIN_LINEAR_BUFSIZE 2048
|
#define MIN_LINEAR_BUFSIZE 2048
|
||||||
#define SUBALLOC_ALIGNMENT sizeof(uintptr_t)
|
#define SUBALLOC_ALIGNMENT sizeof(uintptr_t)
|
||||||
#define LMAGIC 0x87b9c7d3
|
#define LMAGIC 0x87b9c7d3
|
||||||
|
@@ -28,8 +28,6 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define ALIGN(value, align) (((value) + (align) - 1) & ~((align) - 1))
|
|
||||||
|
|
||||||
#define SLAB_MAGIC_ALLOCATED 0xcafe4321
|
#define SLAB_MAGIC_ALLOCATED 0xcafe4321
|
||||||
#define SLAB_MAGIC_FREE 0x7ee01234
|
#define SLAB_MAGIC_FREE 0x7ee01234
|
||||||
|
|
||||||
@@ -109,7 +107,7 @@ slab_create_parent(struct slab_parent_pool *parent,
|
|||||||
unsigned num_items)
|
unsigned num_items)
|
||||||
{
|
{
|
||||||
mtx_init(&parent->mutex, mtx_plain);
|
mtx_init(&parent->mutex, mtx_plain);
|
||||||
parent->element_size = ALIGN(sizeof(struct slab_element_header) + item_size,
|
parent->element_size = ALIGN_POT(sizeof(struct slab_element_header) + item_size,
|
||||||
sizeof(intptr_t));
|
sizeof(intptr_t));
|
||||||
parent->num_elements = num_items;
|
parent->num_elements = num_items;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user