mirror of
https://gitlab.com/suyu-emu/suyu.git
synced 2024-03-15 23:15:44 +00:00
Merge pull request #4497 from lioncash/freezer-alg
freezer: Make use of std::erase_if
This commit is contained in:
commit
a8ffe6eee4
|
@ -107,28 +107,21 @@ void Freezer::Unfreeze(VAddr address) {
|
||||||
|
|
||||||
LOG_DEBUG(Common_Memory, "Unfreezing memory for address={:016X}", address);
|
LOG_DEBUG(Common_Memory, "Unfreezing memory for address={:016X}", address);
|
||||||
|
|
||||||
entries.erase(
|
std::erase_if(entries, [address](const Entry& entry) { return entry.address == address; });
|
||||||
std::remove_if(entries.begin(), entries.end(),
|
|
||||||
[&address](const Entry& entry) { return entry.address == address; }),
|
|
||||||
entries.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Freezer::IsFrozen(VAddr address) const {
|
bool Freezer::IsFrozen(VAddr address) const {
|
||||||
std::lock_guard lock{entries_mutex};
|
std::lock_guard lock{entries_mutex};
|
||||||
|
|
||||||
return std::find_if(entries.begin(), entries.end(), [&address](const Entry& entry) {
|
return FindEntry(address) != entries.cend();
|
||||||
return entry.address == address;
|
|
||||||
}) != entries.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Freezer::SetFrozenValue(VAddr address, u64 value) {
|
void Freezer::SetFrozenValue(VAddr address, u64 value) {
|
||||||
std::lock_guard lock{entries_mutex};
|
std::lock_guard lock{entries_mutex};
|
||||||
|
|
||||||
const auto iter = std::find_if(entries.begin(), entries.end(), [&address](const Entry& entry) {
|
const auto iter = FindEntry(address);
|
||||||
return entry.address == address;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (iter == entries.end()) {
|
if (iter == entries.cend()) {
|
||||||
LOG_ERROR(Common_Memory,
|
LOG_ERROR(Common_Memory,
|
||||||
"Tried to set freeze value for address={:016X} that is not frozen!", address);
|
"Tried to set freeze value for address={:016X} that is not frozen!", address);
|
||||||
return;
|
return;
|
||||||
|
@ -143,11 +136,9 @@ void Freezer::SetFrozenValue(VAddr address, u64 value) {
|
||||||
std::optional<Freezer::Entry> Freezer::GetEntry(VAddr address) const {
|
std::optional<Freezer::Entry> Freezer::GetEntry(VAddr address) const {
|
||||||
std::lock_guard lock{entries_mutex};
|
std::lock_guard lock{entries_mutex};
|
||||||
|
|
||||||
const auto iter = std::find_if(entries.begin(), entries.end(), [&address](const Entry& entry) {
|
const auto iter = FindEntry(address);
|
||||||
return entry.address == address;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (iter == entries.end()) {
|
if (iter == entries.cend()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +151,16 @@ std::vector<Freezer::Entry> Freezer::GetEntries() const {
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Freezer::Entries::iterator Freezer::FindEntry(VAddr address) {
|
||||||
|
return std::find_if(entries.begin(), entries.end(),
|
||||||
|
[address](const Entry& entry) { return entry.address == address; });
|
||||||
|
}
|
||||||
|
|
||||||
|
Freezer::Entries::const_iterator Freezer::FindEntry(VAddr address) const {
|
||||||
|
return std::find_if(entries.begin(), entries.end(),
|
||||||
|
[address](const Entry& entry) { return entry.address == address; });
|
||||||
|
}
|
||||||
|
|
||||||
void Freezer::FrameCallback(std::uintptr_t, std::chrono::nanoseconds ns_late) {
|
void Freezer::FrameCallback(std::uintptr_t, std::chrono::nanoseconds ns_late) {
|
||||||
if (!IsActive()) {
|
if (!IsActive()) {
|
||||||
LOG_DEBUG(Common_Memory, "Memory freezer has been deactivated, ending callback events.");
|
LOG_DEBUG(Common_Memory, "Memory freezer has been deactivated, ending callback events.");
|
||||||
|
|
|
@ -73,13 +73,18 @@ public:
|
||||||
std::vector<Entry> GetEntries() const;
|
std::vector<Entry> GetEntries() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
using Entries = std::vector<Entry>;
|
||||||
|
|
||||||
|
Entries::iterator FindEntry(VAddr address);
|
||||||
|
Entries::const_iterator FindEntry(VAddr address) const;
|
||||||
|
|
||||||
void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
void FrameCallback(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
|
||||||
void FillEntryReads();
|
void FillEntryReads();
|
||||||
|
|
||||||
std::atomic_bool active{false};
|
std::atomic_bool active{false};
|
||||||
|
|
||||||
mutable std::mutex entries_mutex;
|
mutable std::mutex entries_mutex;
|
||||||
std::vector<Entry> entries;
|
Entries entries;
|
||||||
|
|
||||||
std::shared_ptr<Core::Timing::EventType> event;
|
std::shared_ptr<Core::Timing::EventType> event;
|
||||||
Core::Timing::CoreTiming& core_timing;
|
Core::Timing::CoreTiming& core_timing;
|
||||||
|
|
Loading…
Reference in a new issue