ladybird/Kernel/VM/VMObject.cpp
Andreas Kling 0d963fd641 Kernel: Remove unnecessary counting of VMObject-attached Regions
VMObject already has an IntrusiveList of all the Regions that map it.
We were keeping a counter in addition to this, and only using it in
a single place to avoid iterating over the list in case it only had
1 entry.

Simplify VMObject by removing this counter and always iterating the
list even if there's only 1 entry. :^)
2021-07-25 17:28:06 +02:00

38 lines
743 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/VMObject.h>
namespace Kernel {
VMObject::VMObject(VMObject const& other)
: m_physical_pages(other.m_physical_pages)
{
MM.register_vmobject(*this);
}
VMObject::VMObject(size_t size)
: m_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))
{
MM.register_vmobject(*this);
}
VMObject::~VMObject()
{
{
ScopedSpinLock lock(m_on_deleted_lock);
for (auto& it : m_on_deleted)
it->vmobject_deleted(*this);
m_on_deleted.clear();
}
MM.unregister_vmobject(*this);
VERIFY(m_regions.is_empty());
}
}