summaryrefslogtreecommitdiff
path: root/src/common/virtual_buffer.h
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/common/virtual_buffer.h
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/common/virtual_buffer.h')
-rw-r--r--src/common/virtual_buffer.h23
1 files changed, 18 insertions, 5 deletions
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