summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2020-11-17 19:58:41 -0500
committerGravatar Lioncash2020-11-17 20:08:20 -0500
commitb3c8997829ed986c948d195bc1e7c8f66c42755e (patch)
tree9be666d43f15154ee3df2001ced3972cc31a99d7 /src
parentpage_table: Add missing doxygen parameters to Resize() (diff)
downloadyuzu-b3c8997829ed986c948d195bc1e7c8f66c42755e.tar.gz
yuzu-b3c8997829ed986c948d195bc1e7c8f66c42755e.tar.xz
yuzu-b3c8997829ed986c948d195bc1e7c8f66c42755e.zip
page_table: Allow page tables to be moved
Makes page tables and virtual buffers able to be moved, but not copied, making the interface more flexible. Previously, with the destructor specified, but no move assignment or constructor specified, they wouldn't be implicitly generated.
Diffstat (limited to 'src')
-rw-r--r--src/common/page_table.cpp2
-rw-r--r--src/common/page_table.h10
-rw-r--r--src/common/virtual_buffer.cpp4
-rw-r--r--src/common/virtual_buffer.h23
4 files changed, 30 insertions, 9 deletions
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp
index e5d3090d5..bccea0894 100644
--- a/src/common/page_table.cpp
+++ b/src/common/page_table.cpp
@@ -8,7 +8,7 @@ namespace Common {
8 8
9PageTable::PageTable() = default; 9PageTable::PageTable() = default;
10 10
11PageTable::~PageTable() = default; 11PageTable::~PageTable() noexcept = default;
12 12
13void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits, 13void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits,
14 bool has_attribute) { 14 bool has_attribute) {
diff --git a/src/common/page_table.h b/src/common/page_table.h
index a5be7a668..9754fabf9 100644
--- a/src/common/page_table.h
+++ b/src/common/page_table.h
@@ -4,6 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <tuple>
8
7#include "common/common_types.h" 9#include "common/common_types.h"
8#include "common/memory_hook.h" 10#include "common/memory_hook.h"
9#include "common/virtual_buffer.h" 11#include "common/virtual_buffer.h"
@@ -47,7 +49,13 @@ struct SpecialRegion {
47 */ 49 */
48struct PageTable { 50struct PageTable {
49 PageTable(); 51 PageTable();
50 ~PageTable(); 52 ~PageTable() noexcept;
53
54 PageTable(const PageTable&) = delete;
55 PageTable& operator=(const PageTable&) = delete;
56
57 PageTable(PageTable&&) noexcept = default;
58 PageTable& operator=(PageTable&&) noexcept = default;
51 59
52 /** 60 /**
53 * Resizes the page table to be able to accomodate enough pages within 61 * Resizes the page table to be able to accomodate enough pages within
diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp
index b009cb500..e3ca29258 100644
--- a/src/common/virtual_buffer.cpp
+++ b/src/common/virtual_buffer.cpp
@@ -13,7 +13,7 @@
13 13
14namespace Common { 14namespace Common {
15 15
16void* AllocateMemoryPages(std::size_t size) { 16void* AllocateMemoryPages(std::size_t size) noexcept {
17#ifdef _WIN32 17#ifdef _WIN32
18 void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)}; 18 void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)};
19#else 19#else
@@ -29,7 +29,7 @@ void* AllocateMemoryPages(std::size_t size) {
29 return base; 29 return base;
30} 30}
31 31
32void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) { 32void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) noexcept {
33 if (!base) { 33 if (!base) {
34 return; 34 return;
35 } 35 }
diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h
index 125cb42f0..363913d45 100644
--- a/src/common/virtual_buffer.h
+++ b/src/common/virtual_buffer.h
@@ -4,25 +4,38 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "common/common_funcs.h" 7#include <utility>
8 8
9namespace Common { 9namespace Common {
10 10
11void* AllocateMemoryPages(std::size_t size); 11void* AllocateMemoryPages(std::size_t size) noexcept;
12void FreeMemoryPages(void* base, std::size_t size); 12void FreeMemoryPages(void* base, std::size_t size) noexcept;
13 13
14template <typename T> 14template <typename T>
15class VirtualBuffer final : NonCopyable { 15class VirtualBuffer final {
16public: 16public:
17 constexpr VirtualBuffer() = default; 17 constexpr VirtualBuffer() = default;
18 explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} { 18 explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} {
19 base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size)); 19 base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size));
20 } 20 }
21 21
22 ~VirtualBuffer() { 22 ~VirtualBuffer() noexcept {
23 FreeMemoryPages(base_ptr, alloc_size); 23 FreeMemoryPages(base_ptr, alloc_size);
24 } 24 }
25 25
26 VirtualBuffer(const VirtualBuffer&) = delete;
27 VirtualBuffer& operator=(const VirtualBuffer&) = delete;
28
29 VirtualBuffer(VirtualBuffer&& other) noexcept
30 : alloc_size{std::exchange(other.alloc_size, 0)}, base_ptr{std::exchange(other.base_ptr),
31 nullptr} {}
32
33 VirtualBuffer& operator=(VirtualBuffer&& other) noexcept {
34 alloc_size = std::exchange(other.alloc_size, 0);
35 base_ptr = std::exchange(other.base_ptr, nullptr);
36 return *this;
37 }
38
26 void resize(std::size_t count) { 39 void resize(std::size_t count) {
27 FreeMemoryPages(base_ptr, alloc_size); 40 FreeMemoryPages(base_ptr, alloc_size);
28 41