diff --git a/lib/birdlib.h b/lib/birdlib.h index 442bf600..bc7c334c 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -41,7 +41,7 @@ size_t _alignment = _Alignof(typeof(*ptr)); \ ptr = (typeof(ptr)) BIRD_ALIGN((uintptr_t)(val), _alignment); \ } while (0) -#define CPU_STRUCT_ALIGN (MAX_(_Alignof(void*), _Alignof(u64))) +#define CPU_STRUCT_ALIGN (alignof(max_align_t)) #define BIRD_CPU_ALIGN(s) BIRD_ALIGN((s), CPU_STRUCT_ALIGN) /* Structure item alignment macros */ diff --git a/lib/mempool.c b/lib/mempool.c index 1ca6d03b..b88bc122 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -28,8 +28,7 @@ struct lp_chunk { struct lp_chunk *next; struct linpool *lp; - uintptr_t data_align[0]; - _Atomic u64 data_align_atomic[0]; + max_align_t data_align[0]; byte data[0]; }; diff --git a/lib/resource.c b/lib/resource.c index 069e8c4d..8a923792 100644 --- a/lib/resource.c +++ b/lib/resource.c @@ -384,10 +384,7 @@ tmp_flush(void) struct mblock { resource r; unsigned size; - union { - uintptr_t bigint; - _Atomic u64 atom; - } _align[0]; + max_align_t data_align[0]; byte data[0]; }; diff --git a/lib/slab.c b/lib/slab.c index d68bfef1..9351a06d 100644 --- a/lib/slab.c +++ b/lib/slab.c @@ -68,7 +68,7 @@ static struct resclass sl_class = { struct sl_obj { node n; - uintptr_t data_align[0]; + max_align_t data_align[0]; byte data[0]; }; @@ -168,13 +168,6 @@ struct sl_head { u32 used_bits[0]; }; -struct sl_alignment { /* Magic structure for testing of alignment */ - byte data; - int x[0]; - _Atomic u64 y[0]; - void *z[0]; -}; - #define TLIST_PREFIX sl_head #define TLIST_TYPE struct sl_head #define TLIST_ITEM n @@ -221,9 +214,7 @@ slab * sl_new(pool *p, uint size) { slab *s = ralloc(p, &sl_class); - uint align = sizeof(struct sl_alignment); - if (align < sizeof(void *)) - align = sizeof(void *); + uint align = CPU_STRUCT_ALIGN; s->data_size = size; size = (size + align - 1) / align * align; s->obj_size = size;