1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

Kernel: Make PhysicalPage not movable and use atomic ref counting

We should not be moving ref-counted objects.
This commit is contained in:
Tom 2020-08-21 21:49:50 -06:00 committed by Andreas Kling
parent 3320bb45d1
commit 08a569fbe0
5 changed files with 20 additions and 24 deletions

View file

@ -39,29 +39,29 @@ class PhysicalPage {
friend class PageDirectory;
friend class VMObject;
MAKE_SLAB_ALLOCATED(PhysicalPage)
MAKE_SLAB_ALLOCATED(PhysicalPage);
AK_MAKE_NONMOVABLE(PhysicalPage);
public:
PhysicalAddress paddr() const { return m_paddr; }
void ref()
{
ASSERT(m_ref_count);
++m_ref_count;
m_ref_count.fetch_add(1, AK::memory_order_acq_rel);
}
void unref()
{
ASSERT(m_ref_count);
if (!--m_ref_count) {
if (m_ref_count.fetch_sub(1, AK::memory_order_acq_rel) == 1) {
if (m_may_return_to_freelist)
move(*this).return_to_freelist();
return_to_freelist();
delete this;
}
}
static NonnullRefPtr<PhysicalPage> create(PhysicalAddress, bool supervisor, bool may_return_to_freelist = true);
u32 ref_count() const { return m_ref_count; }
u32 ref_count() const { return m_ref_count.load(AK::memory_order_consume); }
bool is_shared_zero_page() const;
@ -69,9 +69,9 @@ private:
PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist = true);
~PhysicalPage() {}
void return_to_freelist() &&;
void return_to_freelist() const;
u32 m_ref_count { 1 };
Atomic<u32> m_ref_count { 1 };
bool m_may_return_to_freelist { true };
bool m_supervisor { false };
PhysicalAddress m_paddr;