From fc26187d9ace9798d9494341f3513eb0840b006d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 3 Dec 2025 20:45:30 +0100 Subject: x86_64/memory: make scoped_mapping swappable --- .../include/x86_64/memory/scoped_mapping.hpp | 4 +++ arch/x86_64/src/memory/scoped_mapping.cpp | 31 +++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'arch') diff --git a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp index 99585bc..d4844fb 100644 --- a/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp +++ b/arch/x86_64/include/x86_64/memory/scoped_mapping.hpp @@ -53,6 +53,8 @@ namespace teachos::memory::x86_64 //! @note If no frame was ever mapped, this function will panic. auto unmap() -> void; + auto swap(scoped_mapping & other) -> void; + private: page m_page; frame_allocator * m_allocator; @@ -60,6 +62,8 @@ namespace teachos::memory::x86_64 std::uint8_t m_allocated; }; + auto swap(scoped_mapping & lhs, scoped_mapping & rhs) -> void; + } // namespace teachos::memory::x86_64 #endif \ No newline at end of file diff --git a/arch/x86_64/src/memory/scoped_mapping.cpp b/arch/x86_64/src/memory/scoped_mapping.cpp index be15330..c9c6459 100644 --- a/arch/x86_64/src/memory/scoped_mapping.cpp +++ b/arch/x86_64/src/memory/scoped_mapping.cpp @@ -44,18 +44,7 @@ namespace teachos::memory::x86_64 auto scoped_mapping::operator=(scoped_mapping && other) noexcept -> scoped_mapping & { - if (&other == this) - { - return *this; - } - - using std::swap; - - swap(m_page, other.m_page); - swap(m_allocator, other.m_allocator); - swap(m_mapped, other.m_mapped); - swap(m_allocated, other.m_allocated); - + this->swap(other); return *this; } @@ -144,4 +133,22 @@ namespace teachos::memory::x86_64 m_mapped = false; } + auto scoped_mapping::swap(scoped_mapping & other) -> void + { + using std::swap; + + if (&other == this) + return; + + swap(m_page, other.m_page); + swap(m_allocator, other.m_allocator); + swap(m_mapped, other.m_mapped); + swap(m_allocated, other.m_allocated); + } + + auto swap(scoped_mapping & lhs, scoped_mapping & rhs) -> void + { + lhs.swap(rhs); + } + } // namespace teachos::memory::x86_64 \ No newline at end of file -- cgit v1.2.3