static Res MFSAlloc(Addr *pReturn, Pool pool, Size size, Bool withReservoirPermit) { Header f; Res res; MFS mfs; AVERT(Pool, pool); mfs = PoolPoolMFS(pool); AVERT(MFS, mfs); AVER(pReturn != NULL); AVER(size == mfs->unroundedUnitSize); AVERT(Bool, withReservoirPermit); f = mfs->freeList; /* If the free list is empty then extend the pool with a new region. */ if(f == NULL) { Addr base; if (!mfs->extendSelf) return ResLIMIT; /* Create a new region and attach it to the pool. */ res = ArenaAlloc(&base, SegPrefDefault(), mfs->extendBy, pool, withReservoirPermit); if(res != ResOK) return res; MFSExtend(pool, base, mfs->extendBy); /* The first unit in the region is now the head of the new free list. */ f = mfs->freeList; } AVER(f != NULL); /* Detach the first free unit from the free list and return its address. */ mfs->freeList = f->next; AVER(mfs->free >= mfs->unitSize); mfs->free -= mfs->unitSize; *pReturn = (Addr)f; return ResOK; }
static Res MFSAlloc(Addr *pReturn, Pool pool, Size size) { MFS mfs = MustBeA(MFSPool, pool); Header f; Res res; AVER(pReturn != NULL); AVER(size == mfs->unroundedUnitSize); f = mfs->freeList; /* If the free list is empty then extend the pool with a new region. */ if(f == NULL) { Addr base; /* See design.mps.bootstrap.land.sol.pool. */ if (!mfs->extendSelf) return ResLIMIT; /* Create a new region and attach it to the pool. */ res = ArenaAlloc(&base, LocusPrefDefault(), mfs->extendBy, pool); if(res != ResOK) return res; MFSExtend(pool, base, mfs->extendBy); /* The first unit in the region is now the head of the new free list. */ f = mfs->freeList; } AVER(f != NULL); /* Detach the first free unit from the free list and return its address. */ mfs->freeList = f->next; AVER(mfs->free >= mfs->unitSize); mfs->free -= mfs->unitSize; *pReturn = (Addr)f; return ResOK; }