Skip to content

Commit

Permalink
Merge pull request #247 from apple/revert-242-sizeof
Browse files Browse the repository at this point in the history
Revert "Use sizeof more pervasively"
  • Loading branch information
das committed May 19, 2017
2 parents d6eb245 + c717a44 commit e85f5ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,10 @@ _dispatch_alloc_init(void)
// Double-check our math. These are all compile time checks and don't
// generate code.

dispatch_assert(sizeof(bitmap_t) == BYTES_PER_BITMAP);
dispatch_assert(sizeof(bitmap_t) == BYTES_PER_SUPERMAP);
dispatch_assert(sizeof(struct dispatch_magazine_header_s) ==
SIZEOF_HEADER);

dispatch_assert(sizeof(struct dispatch_continuation_s) <=
DISPATCH_CONTINUATION_SIZE);
Expand All @@ -611,6 +614,8 @@ _dispatch_alloc_init(void)
dispatch_assert(sizeof(struct dispatch_magazine_s) == BYTES_PER_MAGAZINE);

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

Expand Down
18 changes: 13 additions & 5 deletions src/allocator_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,25 @@
// Use the largest type your platform is comfortable doing atomic ops with.
// TODO: rdar://11477843
typedef unsigned long bitmap_t;
#define BYTES_PER_BITMAP sizeof(bitmap_t)
#if defined(__LP64__)
#define BYTES_PER_BITMAP 8
#else
#define BYTES_PER_BITMAP 4
#endif

#define BITMAP_C(v) ((bitmap_t)(v))
#define BITMAP_ALL_ONES (~BITMAP_C(0))

// Stop configuring.

#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * CHAR_BIT)
#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * CHAR_BIT)
#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * 8)
#define BITMAPS_PER_SUPERMAP (BYTES_PER_SUPERMAP * 8)

#define BYTES_PER_MAGAZINE (PAGES_PER_MAGAZINE * DISPATCH_ALLOCATOR_PAGE_SIZE)
#define CONSUMED_BYTES_PER_BITMAP (BYTES_PER_BITMAP + \
(DISPATCH_CONTINUATION_SIZE * CONTINUATIONS_PER_BITMAP))

#define BYTES_PER_SUPERMAP sizeof(bitmap_t)
#define BYTES_PER_SUPERMAP BYTES_PER_BITMAP
#define CONSUMED_BYTES_PER_SUPERMAP (BYTES_PER_SUPERMAP + \
(BITMAPS_PER_SUPERMAP * CONSUMED_BYTES_PER_BITMAP))

Expand Down Expand Up @@ -143,7 +147,11 @@ typedef unsigned long bitmap_t;

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

#define SIZEOF_HEADER (sizeof(struct dispatch_magazine_header_s))
#if defined(__LP64__)
#define SIZEOF_HEADER 16
#else
#define SIZEOF_HEADER 8
#endif

#define SIZEOF_SUPERMAPS (BYTES_PER_SUPERMAP * SUPERMAPS_PER_MAGAZINE)
#define SIZEOF_MAPS (BYTES_PER_BITMAP * BITMAPS_PER_SUPERMAP * \
Expand Down

0 comments on commit e85f5ee

Please sign in to comment.