From e4146ec3a193515692c60eabdea3d1db8044bb47 Mon Sep 17 00:00:00 2001 From: Fernando S Date: Tue, 5 Oct 2021 16:06:41 +0200 Subject: [PATCH] x64 Interface: Allow for asynchronous invalidation (#647) * x64 Interface: Make Invalidation asynchronous. * Apply suggestions from code review --- src/dynarmic/backend/x64/a64_interface.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/dynarmic/backend/x64/a64_interface.cpp b/src/dynarmic/backend/x64/a64_interface.cpp index 26713a9c..cb4ed12a 100644 --- a/src/dynarmic/backend/x64/a64_interface.cpp +++ b/src/dynarmic/backend/x64/a64_interface.cpp @@ -5,6 +5,7 @@ #include #include +#include #include @@ -57,6 +58,8 @@ public: void Run() { ASSERT(!is_executing); + PerformRequestedCacheInvalidation(); + is_executing = true; SCOPE_EXIT { this->is_executing = false; }; jit_state.halt_requested = false; @@ -80,6 +83,8 @@ public: void Step() { ASSERT(!is_executing); + PerformRequestedCacheInvalidation(); + is_executing = true; SCOPE_EXIT { this->is_executing = false; }; jit_state.halt_requested = true; @@ -90,15 +95,21 @@ public: } void ClearCache() { + std::unique_lock lock{invalidation_mutex}; invalidate_entire_cache = true; - RequestCacheInvalidation(); + if (is_executing) { + jit_state.halt_requested = true; + } } void InvalidateCacheRange(u64 start_address, size_t length) { + std::unique_lock lock{invalidation_mutex}; const auto end_address = static_cast(start_address + length - 1); const auto range = boost::icl::discrete_interval::closed(start_address, end_address); invalid_cache_ranges.add(range); - RequestCacheInvalidation(); + if (is_executing) { + jit_state.halt_requested = true; + } } void Reset() { @@ -268,6 +279,7 @@ private: } void PerformRequestedCacheInvalidation() { + std::unique_lock lock{invalidation_mutex}; if (!invalidate_entire_cache && invalid_cache_ranges.empty()) { return; } @@ -292,6 +304,7 @@ private: bool invalidate_entire_cache = false; boost::icl::interval_set invalid_cache_ranges; + std::mutex invalidation_mutex; }; Jit::Jit(UserConfig conf)