aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2025-12-03 20:45:30 +0100
committerFelix Morgner <felix.morgner@ost.ch>2025-12-03 20:45:30 +0100
commitfc26187d9ace9798d9494341f3513eb0840b006d (patch)
tree6874a6c869376e8c3768fc2594f438a56e3d1136
parentf3dd2b2f5bd1b5dd4d4309a30db3c7733b8f63bb (diff)
downloadteachos-fc26187d9ace9798d9494341f3513eb0840b006d.tar.xz
teachos-fc26187d9ace9798d9494341f3513eb0840b006d.zip
x86_64/memory: make scoped_mapping swappable
-rw-r--r--arch/x86_64/include/x86_64/memory/scoped_mapping.hpp4
-rw-r--r--arch/x86_64/src/memory/scoped_mapping.cpp31
2 files changed, 23 insertions, 12 deletions
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