Previously we asserted every time you tried to pack a pointer and a counter
together. However, this wasn't really correct. In the case where you try
to grab the last element of the list, the "next elemnet" value you get may
be bogus if someonoe else got there first. This was leading to assertion
failures even though the allocator would safely fall through to the failure
case below.
#define PFL_COUNT(x) ((uintptr_t)(x) & 0xfff)
#define PFL_PTR(x) ((void *)((uintptr_t)(x) & ~0xfff))
#define PFL_PACK(ptr, count) ({ \
- assert(((uintptr_t)(ptr) & 0xfff) == 0); \
(void *)((uintptr_t)(ptr) | (uintptr_t)((count) & 0xfff)); \
})
void *old, *current;
void **next_ptr = elem;
+ /* The pointer-based free list requires that the pointer be
+ * page-aligned. This is because we use the bottom 12 bits of the
+ * pointer to store a counter to solve the ABA concurrency problem.
+ */
+ assert(((uintptr_t)elem & 0xfff) == 0);
+
old = *list;
do {
current = old;