1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

Kernel: Remove Range "valid" state and use Optional<Range> instead

It's easier to understand VM ranges if they are always valid. We can
simply use an empty Optional<Range> to encode absence when needed.
This commit is contained in:
Andreas Kling 2021-01-27 21:01:45 +01:00
parent 67bc5e0bbd
commit e67402c702
8 changed files with 39 additions and 37 deletions

View file

@ -36,6 +36,7 @@
namespace Kernel {
RangeAllocator::RangeAllocator()
: m_total_range({}, 0)
{
}
@ -105,7 +106,7 @@ void RangeAllocator::carve_at_index(int index, const Range& range)
m_available_ranges.insert(index + 1, move(remaining_parts[1]));
}
Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
Optional<Range> RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
{
if (!size)
return {};
@ -148,7 +149,7 @@ Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
return {};
}
Range RangeAllocator::allocate_specific(VirtualAddress base, size_t size)
Optional<Range> RangeAllocator::allocate_specific(VirtualAddress base, size_t size)
{
if (!size)
return {};
@ -178,7 +179,7 @@ Range RangeAllocator::allocate_specific(VirtualAddress base, size_t size)
return {};
}
void RangeAllocator::deallocate(Range range)
void RangeAllocator::deallocate(const Range& range)
{
ScopedSpinLock lock(m_lock);
ASSERT(m_total_range.contains(range));