sb_span *active_sb;
Size fclass;
Size nmax = (FPM_PAGE_SIZE * SB_PAGES_PER_SUPERBLOCK) / obsize;
+ char *superblock;
+ char *result;
/*
* If fullness class 1 is empty, try to find something to put in it by
return NULL;
}
- /* We have a superblock from which to allocate; do it. */
+ /*
+ * There should be a superblock in fullness class 1 at this point, and
+ * it should never be completely full. Thus we can either pop the
+ * free list or, failing that, initialize a new object.
+ */
active_sb = relptr_access(base, heap->spans[1]);
+ superblock = base + active_sb->first_page * FPM_PAGE_SIZE;
Assert(active_sb != NULL);
- /* XXX need to actually allocate something here! */
+ Assert(active_sb->nused < nmax);
+ Assert(active_sb->nused < active_sb->ninitialized);
+ if (active_sb->firstfree < nmax)
+ {
+ result = superblock + active_sb->firstfree * obsize;
+ active_sb->firstfree = * (Size *) result;
+ }
+ else
+ {
+ Assert(active_sb->ninitialized < nmax);
+ result = superblock + active_sb->ninitialized * obsize;
+ ++active_sb->ninitialized;
+ }
/* If it's now full, move it to the highest-numbered fullness class. */
if (active_sb->nused == nmax)
sb_transfer_first_span(base, heap, 1, SB_FULLNESS_CLASSES - 1);
- return NULL; /* XXX */
+ return result;
}
/*
span->size_class = size_class;
span->ninitialized = 0;
span->nused = 0;
- span->firstfree = 0;
+ span->firstfree = (uint16) -1;
}
/*