]> git.saurik.com Git - apple/libdispatch.git/blobdiff - src/allocator_internal.h
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / src / allocator_internal.h
index f4c8ba0de3ab0d74f95a2673e99762075cd93398..abe4a1d438a3bc744a986b1917a9bdeb668ab645 100644 (file)
 #endif
 #endif
 
-#if TARGET_IPHONE_SIMULATOR && IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1090
-#undef DISPATCH_USE_NANOZONE
-#define DISPATCH_USE_NANOZONE 0
-#endif
 #ifndef DISPATCH_USE_NANOZONE
-#if TARGET_OS_MAC && defined(__LP64__) && \
-               (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 || \
-               __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000)
+#if TARGET_OS_MAC && defined(__LP64__)
 #define DISPATCH_USE_NANOZONE 1
 #endif
 #endif
@@ -141,6 +135,16 @@ typedef unsigned long bitmap_t;
 #define HEAP_MASK (~(uintptr_t)(BYTES_PER_HEAP - 1))
 #define MAGAZINE_MASK (~(uintptr_t)(BYTES_PER_MAGAZINE - 1))
 
+// this will round up such that first_bitmap_in_same_page() can mask the address
+// of a bitmap_t in the maps to obtain the first bitmap for that same page
+#define ROUND_UP_TO_BITMAP_ALIGNMENT(x) \
+               (((x) + ((BITMAPS_PER_PAGE * BYTES_PER_BITMAP) - 1u)) & \
+               ~((BITMAPS_PER_PAGE * BYTES_PER_BITMAP) - 1u))
+// Since these are both powers of two, we end up with not only the max alignment,
+// but happily the least common multiple, which will be the greater of the two.
+#define ROUND_UP_TO_BITMAP_ALIGNMENT_AND_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(ROUND_UP_TO_BITMAP_ALIGNMENT(x)))
+#define PADDING_TO_BITMAP_ALIGNMENT_AND_CONTINUATION_SIZE(x) (ROUND_UP_TO_BITMAP_ALIGNMENT_AND_CONTINUATION_SIZE(x) - (x))
+
 #define PADDING_TO_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(x) - (x))
 
 #if defined(__LP64__)
@@ -155,8 +159,11 @@ typedef unsigned long bitmap_t;
 
 // header is expected to end on supermap's required alignment
 #define HEADER_TO_SUPERMAPS_PADDING 0
-#define SUPERMAPS_TO_MAPS_PADDING (PADDING_TO_CONTINUATION_SIZE( \
+// we want to align the maps to a continuation size, but we must also have proper padding
+// so that we can perform first_bitmap_in_same_page()
+#define SUPERMAPS_TO_MAPS_PADDING (PADDING_TO_BITMAP_ALIGNMENT_AND_CONTINUATION_SIZE( \
                SIZEOF_SUPERMAPS + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_HEADER))
+
 #define MAPS_TO_FPMAPS_PADDING (PADDING_TO_CONTINUATION_SIZE(SIZEOF_MAPS))
 
 #define BYTES_LEFT_IN_FIRST_PAGE (BYTES_PER_PAGE - \
@@ -205,7 +212,7 @@ struct dispatch_magazine_header_s {
        // Link to the next heap in the chain. Only used in magazine 0's header
        dispatch_heap_t dh_next;
 
-       // Points to the first bitmap in the page where this CPU succesfully
+       // Points to the first bitmap in the page where this CPU successfully
        // allocated a continuation last time. Only used in the first heap.
        bitmap_t *last_found_page;
 };