From ae5311d6e60d817be6a9734ab867003561e7d6bc Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 25 Feb 2023 16:08:52 +0100 Subject: [PATCH] PowerPC: Rework CPUThreadGuard handling in Expression.cpp See https://github.com/dolphin-emu/dolphin/pull/11554#discussion_r1113949572. --- Source/Core/Core/PowerPC/Expression.cpp | 32 ++++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/PowerPC/Expression.cpp b/Source/Core/Core/PowerPC/Expression.cpp index ce8cdcd240..6da5188e86 100644 --- a/Source/Core/Core/PowerPC/Expression.cpp +++ b/Source/Core/Core/PowerPC/Expression.cpp @@ -81,9 +81,10 @@ static double HostReadFunc(expr_func* f, vec_expr_t* args, void* c) { if (vec_len(args) != 1) return 0; - const auto* guard = reinterpret_cast(c); const u32 address = static_cast(expr_eval(&vec_nth(args, 0))); - return Common::BitCast(HostRead(*guard, address)); + + Core::CPUThreadGuard guard; + return Common::BitCast(HostRead(guard, address)); } template @@ -91,10 +92,11 @@ static double HostWriteFunc(expr_func* f, vec_expr_t* args, void* c) { if (vec_len(args) != 2) return 0; - const auto* guard = reinterpret_cast(c); const T var = static_cast(expr_eval(&vec_nth(args, 0))); const u32 address = static_cast(expr_eval(&vec_nth(args, 1))); - HostWrite(*guard, Common::BitCast(var), address); + + Core::CPUThreadGuard guard; + HostWrite(guard, Common::BitCast(var), address); return var; } @@ -112,10 +114,12 @@ static double CallstackFunc(expr_func* f, vec_expr_t* args, void* c) return 0; std::vector stack; - const auto* guard = reinterpret_cast(c); - bool success = Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), *guard, stack); - if (!success) - return 0; + { + Core::CPUThreadGuard guard; + bool success = Dolphin_Debugger::GetCallstack(Core::System::GetInstance(), guard, stack); + if (!success) + return 0; + } double num = expr_eval(&vec_nth(args, 0)); if (!std::isnan(num)) @@ -158,11 +162,11 @@ static double StreqFunc(expr_func* f, vec_expr_t* args, void* c) if (vec_len(args) != 2) return 0; - const auto* guard = reinterpret_cast(c); std::array strs; + Core::CPUThreadGuard guard; for (int i = 0; i < 2; i++) { - std::optional arg = ReadStringArg(*guard, &vec_nth(args, i)); + std::optional arg = ReadStringArg(guard, &vec_nth(args, i)); if (arg == std::nullopt) return 0; @@ -266,13 +270,7 @@ double Expression::Evaluate() const { SynchronizeBindings(SynchronizeDirection::From); - double result; - { - Core::CPUThreadGuard guard; - m_expr->param.func.context = &guard; - result = expr_eval(m_expr.get()); - m_expr->param.func.context = nullptr; - } + double result = expr_eval(m_expr.get()); SynchronizeBindings(SynchronizeDirection::To);