static char *
mspan_allocate_from_superblock(char *base, mspan *superblock)
{
+ char *spanbase;
+ uint16 object_size;
+ uint16 total;
+
+ /* Quick exit if there are no free objects. */
+ object_size = mspan_size_classes[superblock->span_type];
+ total = MSPAN_SUPERBLOCK_SIZE / object_size;
+ if (superblock->nused >= total)
+ return NULL;
+
+ /* Try to reuse a previously-freed object. */
+ spanbase = base + superblock->first_page * MSPAN_PAGE_SIZE;
+ if (superblock->firstfree != MSPAN_FIRSTFREE_NONE)
+ {
+ uint16 *firstfree;
+
+ firstfree =
+ (uint16 *) (spanbase + (superblock->firstfree * object_size));
+ superblock->firstfree = *firstfree;
+ return (char *) firstfree;
+ }
+
+ /*
+ * Carve out space from the uninitialized portion of the span. This
+ * should always work, since we already verified that nused < total.
+ */
+
/*
* XXX. Implementation needed.
*/