Skip to content

Commit ac31fd0

Browse files
committed
allocator: use the compiler to compute header size
Rather than trying to compute the size of the magazine header manually, use the compiler's builtin `sizeof` operator.
1 parent 8561ed3 commit ac31fd0

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/allocator.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,6 @@ _dispatch_alloc_init(void)
603603

604604
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_BITMAP);
605605
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_SUPERMAP);
606-
dispatch_assert(sizeof(struct dispatch_magazine_header_s) ==
607-
SIZEOF_HEADER);
608606

609607
dispatch_assert(sizeof(struct dispatch_continuation_s) <=
610608
DISPATCH_CONTINUATION_SIZE);
@@ -614,8 +612,6 @@ _dispatch_alloc_init(void)
614612
dispatch_assert(sizeof(struct dispatch_magazine_s) == BYTES_PER_MAGAZINE);
615613

616614
// The header and maps sizes should match what we computed.
617-
dispatch_assert(SIZEOF_HEADER ==
618-
sizeof(((struct dispatch_magazine_s *)0x0)->header));
619615
dispatch_assert(SIZEOF_MAPS ==
620616
sizeof(((struct dispatch_magazine_s *)0x0)->maps));
621617

src/allocator_internal.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ typedef unsigned long bitmap_t;
147147

148148
#define PADDING_TO_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(x) - (x))
149149

150-
#if defined(__LP64__)
151-
#define SIZEOF_HEADER 16
152-
#else
153-
#define SIZEOF_HEADER 8
154-
#endif
155-
156150
#define SIZEOF_SUPERMAPS (BYTES_PER_SUPERMAP * SUPERMAPS_PER_MAGAZINE)
157151
#define SIZEOF_MAPS (BYTES_PER_BITMAP * BITMAPS_PER_SUPERMAP * \
158152
SUPERMAPS_PER_MAGAZINE)
@@ -162,12 +156,12 @@ typedef unsigned long bitmap_t;
162156
// we want to align the maps to a continuation size, but we must also have proper padding
163157
// so that we can perform first_bitmap_in_same_page()
164158
#define SUPERMAPS_TO_MAPS_PADDING (PADDING_TO_BITMAP_ALIGNMENT_AND_CONTINUATION_SIZE( \
165-
SIZEOF_SUPERMAPS + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_HEADER))
159+
SIZEOF_SUPERMAPS + HEADER_TO_SUPERMAPS_PADDING + sizeof(struct dispatch_magazine_header_s)))
166160

167161
#define MAPS_TO_FPMAPS_PADDING (PADDING_TO_CONTINUATION_SIZE(SIZEOF_MAPS))
168162

169163
#define BYTES_LEFT_IN_FIRST_PAGE (BYTES_PER_PAGE - \
170-
(SIZEOF_HEADER + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_SUPERMAPS + \
164+
(sizeof(struct dispatch_magazine_header_s) + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_SUPERMAPS + \
171165
SUPERMAPS_TO_MAPS_PADDING + SIZEOF_MAPS + MAPS_TO_FPMAPS_PADDING))
172166

173167
#if PACK_FIRST_PAGE_WITH_CONTINUATIONS

0 commit comments

Comments
 (0)