From eb419802e27333e7bf0971be5ada5d96c1c6cf97 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 14 Apr 2016 10:42:14 -0400 Subject: [PATCH] Flatten the frame allocator routine --- src/memory/FrameAllocator.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/memory/FrameAllocator.cc b/src/memory/FrameAllocator.cc index 55c3413..9d1111b 100644 --- a/src/memory/FrameAllocator.cc +++ b/src/memory/FrameAllocator.cc @@ -54,17 +54,20 @@ FrameAllocator::allocate() const u32 pagesPerBitmap = Bitmap::length; for (usize i = 0; i < mNumberOfPages; i++) { auto bitmap = mBitmap[i]; - if (!bitmap.isFull()) { - kstd::printFormat("Found partially full bitmap %ld -> %02X\n", i, u8(bitmap)); - for (usize j = 0; j < pagesPerBitmap; j++) { - if (!bitmap.isSet(j)) { - bitmap.set(j); - usize page = i * pagesPerBitmap + j; - void* pageAddress = addressOfPage(page); - kstd::printFormat("Allocating frame for page %ld at address 0x%08lX\n", page, u32(pageAddress)); - return pageAddress; - } + if (bitmap.isFull()) { + continue; + } + kstd::printFormat("Found partially full bitmap %ld -> %02X\n", i, u8(bitmap)); + for (usize j = 0; j < pagesPerBitmap; j++) { + if (bitmap.isSet(j)) { + continue; } + kstd::printFormat("Found unset bit %ld\n", j); + bitmap.set(j); + usize page = i * pagesPerBitmap + j; + void* pageAddress = addressOfPage(page); + kstd::printFormat("Allocating frame for page %ld at address 0x%08lX\n", page, u32(pageAddress)); + return pageAddress; } } kstd::printFormat("Couldn't allocate frame\n");