diff options
| -rw-r--r-- | src/common/virtual_buffer.cpp | 9 | ||||
| -rw-r--r-- | src/core/tools/freezer.cpp | 31 | ||||
| -rw-r--r-- | src/core/tools/freezer.h | 7 |
3 files changed, 22 insertions, 25 deletions
diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp index be5b67752..b009cb500 100644 --- a/src/common/virtual_buffer.cpp +++ b/src/common/virtual_buffer.cpp | |||
| @@ -5,16 +5,7 @@ | |||
| 5 | #ifdef _WIN32 | 5 | #ifdef _WIN32 |
| 6 | #include <windows.h> | 6 | #include <windows.h> |
| 7 | #else | 7 | #else |
| 8 | #include <stdio.h> | ||
| 9 | #include <sys/mman.h> | 8 | #include <sys/mman.h> |
| 10 | #include <sys/types.h> | ||
| 11 | #if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__ | ||
| 12 | #include <sys/sysctl.h> | ||
| 13 | #elif defined __HAIKU__ | ||
| 14 | #include <OS.h> | ||
| 15 | #else | ||
| 16 | #include <sys/sysinfo.h> | ||
| 17 | #endif | ||
| 18 | #endif | 9 | #endif |
| 19 | 10 | ||
| 20 | #include "common/assert.h" | 11 | #include "common/assert.h" |
diff --git a/src/core/tools/freezer.cpp b/src/core/tools/freezer.cpp index 2003e096f..5c674a099 100644 --- a/src/core/tools/freezer.cpp +++ b/src/core/tools/freezer.cpp | |||
| @@ -107,28 +107,21 @@ void Freezer::Unfreeze(VAddr address) { | |||
| 107 | 107 | ||
| 108 | LOG_DEBUG(Common_Memory, "Unfreezing memory for address={:016X}", address); | 108 | LOG_DEBUG(Common_Memory, "Unfreezing memory for address={:016X}", address); |
| 109 | 109 | ||
| 110 | entries.erase( | 110 | std::erase_if(entries, [address](const Entry& entry) { return entry.address == address; }); |
| 111 | std::remove_if(entries.begin(), entries.end(), | ||
| 112 | [&address](const Entry& entry) { return entry.address == address; }), | ||
| 113 | entries.end()); | ||
| 114 | } | 111 | } |
| 115 | 112 | ||
| 116 | bool Freezer::IsFrozen(VAddr address) const { | 113 | bool Freezer::IsFrozen(VAddr address) const { |
| 117 | std::lock_guard lock{entries_mutex}; | 114 | std::lock_guard lock{entries_mutex}; |
| 118 | 115 | ||
| 119 | return std::find_if(entries.begin(), entries.end(), [&address](const Entry& entry) { | 116 | return FindEntry(address) != entries.cend(); |
| 120 | return entry.address == address; | ||
| 121 | }) != entries.end(); | ||
| 122 | } | 117 | } |
| 123 | 118 | ||
| 124 | void Freezer::SetFrozenValue(VAddr address, u64 value) { | 119 | void Freezer::SetFrozenValue(VAddr address, u64 value) { |
| 125 | std::lock_guard lock{entries_mutex}; | 120 | std::lock_guard lock{entries_mutex}; |
| 126 | 121 | ||
| 127 | const auto iter = std::find_if(entries.begin(), entries.end(), [&address](const Entry& entry) { | 122 | const auto iter = FindEntry(address); |
| 128 | return entry.address == address; | ||
| 129 | }); | ||
| 130 | 123 | ||
| 131 | if (iter == entries.end()) { | 124 | if (iter == entries.cend()) { |
| 132 | LOG_ERROR(Common_Memory, | 125 | LOG_ERROR(Common_Memory, |
| 133 | "Tried to set freeze value for address={:016X} that is not frozen!", address); | 126 | "Tried to set freeze value for address={:016X} that is not frozen!", address); |
| 134 | return; | 127 | return; |
| @@ -143,11 +136,9 @@ void Freezer::SetFrozenValue(VAddr address, u64 value) { | |||
| 143 | std::optional<Freezer::Entry> Freezer::GetEntry(VAddr address) const { | 136 | std::optional<Freezer::Entry> Freezer::GetEntry(VAddr address) const { |
| 144 | std::lock_guard lock{entries_mutex}; | 137 | std::lock_guard lock{entries_mutex}; |
| 145 | 138 | ||
| 146 | const auto iter = std::find_if(entries.begin(), entries.end(), [&address](const Entry& entry) { | 139 | const auto iter = FindEntry(address); |
| 147 | return entry.address == address; | ||
| 148 | }); | ||
| 149 | 140 | ||
| 150 | if (iter == entries.end()) { | 141 | if (iter == entries.cend()) { |
| 151 | return std::nullopt; | 142 | return std::nullopt; |
| 152 | } | 143 | } |
| 153 | 144 | ||
| @@ -160,6 +151,16 @@ std::vector<Freezer::Entry> Freezer::GetEntries() const { | |||
| 160 | return entries; | 151 | return entries; |
| 161 | } | 152 | } |
| 162 | 153 | ||
| 154 | Freezer::Entries::iterator Freezer::FindEntry(VAddr address) { | ||
| 155 | return std::find_if(entries.begin(), entries.end(), | ||
| 156 | [address](const Entry& entry) { return entry.address == address; }); | ||
| 157 | } | ||
| 158 | |||
| 159 | Freezer::Entries::const_iterator Freezer::FindEntry(VAddr address) const { | ||
| 160 | return std::find_if(entries.begin(), entries.end(), | ||
| 161 | [address](const Entry& entry) { return entry.address == address; }); | ||
| 162 | } | ||
| 163 | |||
| 163 | void Freezer::FrameCallback(std::uintptr_t, std::chrono::nanoseconds ns_late) { | 164 | void Freezer::FrameCallback(std::uintptr_t, std::chrono::nanoseconds ns_late) { |
| 164 | if (!IsActive()) { | 165 | if (!IsActive()) { |
| 165 | LOG_DEBUG(Common_Memory, "Memory freezer has been deactivated, ending callback events."); | 166 | LOG_DEBUG(Common_Memory, "Memory freezer has been deactivated, ending callback events."); |
diff --git a/src/core/tools/freezer.h b/src/core/tools/freezer.h index 2b2326bc4..0fdb701a7 100644 --- a/src/core/tools/freezer.h +++ b/src/core/tools/freezer.h | |||
| @@ -73,13 +73,18 @@ public: | |||
| 73 | std::vector<Entry> GetEntries() const; | 73 | std::vector<Entry> GetEntries() const; |
| 74 | 74 | ||
| 75 | private: | 75 | private: |
| 76 | using Entries = std::vector<Entry>; | ||
| 77 | |||
| 78 | Entries::iterator FindEntry(VAddr address); | ||
| 79 | Entries::const_iterator FindEntry(VAddr address) const; | ||
| 80 | |||
| 76 | void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); | 81 | void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); |
| 77 | void FillEntryReads(); | 82 | void FillEntryReads(); |
| 78 | 83 | ||
| 79 | std::atomic_bool active{false}; | 84 | std::atomic_bool active{false}; |
| 80 | 85 | ||
| 81 | mutable std::mutex entries_mutex; | 86 | mutable std::mutex entries_mutex; |
| 82 | std::vector<Entry> entries; | 87 | Entries entries; |
| 83 | 88 | ||
| 84 | std::shared_ptr<Core::Timing::EventType> event; | 89 | std::shared_ptr<Core::Timing::EventType> event; |
| 85 | Core::Timing::CoreTiming& core_timing; | 90 | Core::Timing::CoreTiming& core_timing; |