From ad1f37890267152ef7dac1ad4c193c5bf1eae690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 31 Aug 2023 11:10:02 +0200 Subject: [PATCH] Also simplify __CtrlUpdateButtons to only do a single read and write to the global. --- Core/HLE/sceCtrl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 3c5ca06055..9b43750236 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -206,9 +206,12 @@ u32 __CtrlReadLatch() void __CtrlUpdateButtons(u32 bitsToSet, u32 bitsToClear) { + bitsToClear &= CTRL_MASK_USER; + bitsToSet &= CTRL_MASK_USER; + std::lock_guard guard(ctrlMutex); - ctrlCurrent.buttons &= ~(bitsToClear & CTRL_MASK_USER); - ctrlCurrent.buttons |= (bitsToSet & CTRL_MASK_USER); + // There's no atomic operation for this, so mutex it is. + ctrlCurrent.buttons = (ctrlCurrent.buttons & ~bitsToClear) | bitsToSet; } void __CtrlSetAnalogXY(int stick, float x, float y)