mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 09:15:08 +00:00

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. :^)
37 lines
743 B
C++
37 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());
|
|
}
|
|
|
|
}
|