Skip to content

Use sizeof more pervasively #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,7 @@ _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 @@ -614,8 +611,6 @@ _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: 5 additions & 13 deletions src/allocator_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,21 @@
// Use the largest type your platform is comfortable doing atomic ops with.
// TODO: rdar://11477843
typedef unsigned long bitmap_t;
#if defined(__LP64__)
#define BYTES_PER_BITMAP 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the other guy, makes this sizeof(bitmap_t)

#else
#define BYTES_PER_BITMAP 4
#endif
#define BYTES_PER_BITMAP sizeof(bitmap_t)

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

// Stop configuring.

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

#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 BYTES_PER_BITMAP
#define BYTES_PER_SUPERMAP sizeof(bitmap_t)
#define CONSUMED_BYTES_PER_SUPERMAP (BYTES_PER_SUPERMAP + \
(BITMAPS_PER_SUPERMAP * CONSUMED_BYTES_PER_BITMAP))

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

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

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

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