diff options
| author | 2022-04-02 00:02:31 -0600 | |
|---|---|---|
| committer | 2022-04-07 13:18:03 -0500 | |
| commit | fa5277ecdb363f22f31ad4d0b981e12dde4eed0e (patch) | |
| tree | f8614e39d71c50c363a618945232af2a3e017627 /src/core/hid/emulated_console.cpp | |
| parent | Merge pull request #8164 from liamwhite/jit-stub (diff) | |
| download | yuzu-fa5277ecdb363f22f31ad4d0b981e12dde4eed0e.tar.gz yuzu-fa5277ecdb363f22f31ad4d0b981e12dde4eed0e.tar.xz yuzu-fa5277ecdb363f22f31ad4d0b981e12dde4eed0e.zip | |
core: hid: Reduce the amount of dataraces
Diffstat (limited to 'src/core/hid/emulated_console.cpp')
| -rw-r--r-- | src/core/hid/emulated_console.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index eef0ff493..639f61809 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp | |||
| @@ -132,7 +132,7 @@ void EmulatedConsole::SetMotionParam(Common::ParamPackage param) { | |||
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) { | 134 | void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) { |
| 135 | std::lock_guard lock{mutex}; | 135 | std::unique_lock lock{mutex}; |
| 136 | auto& raw_status = console.motion_values.raw_status; | 136 | auto& raw_status = console.motion_values.raw_status; |
| 137 | auto& emulated = console.motion_values.emulated; | 137 | auto& emulated = console.motion_values.emulated; |
| 138 | 138 | ||
| @@ -151,6 +151,7 @@ void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) { | |||
| 151 | emulated.UpdateOrientation(raw_status.delta_timestamp); | 151 | emulated.UpdateOrientation(raw_status.delta_timestamp); |
| 152 | 152 | ||
| 153 | if (is_configuring) { | 153 | if (is_configuring) { |
| 154 | lock.unlock(); | ||
| 154 | TriggerOnChange(ConsoleTriggerType::Motion); | 155 | TriggerOnChange(ConsoleTriggerType::Motion); |
| 155 | return; | 156 | return; |
| 156 | } | 157 | } |
| @@ -166,6 +167,7 @@ void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) { | |||
| 166 | // Find what is this value | 167 | // Find what is this value |
| 167 | motion.verticalization_error = 0.0f; | 168 | motion.verticalization_error = 0.0f; |
| 168 | 169 | ||
| 170 | lock.unlock(); | ||
| 169 | TriggerOnChange(ConsoleTriggerType::Motion); | 171 | TriggerOnChange(ConsoleTriggerType::Motion); |
| 170 | } | 172 | } |
| 171 | 173 | ||
| @@ -173,11 +175,12 @@ void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, st | |||
| 173 | if (index >= console.touch_values.size()) { | 175 | if (index >= console.touch_values.size()) { |
| 174 | return; | 176 | return; |
| 175 | } | 177 | } |
| 176 | std::lock_guard lock{mutex}; | 178 | std::unique_lock lock{mutex}; |
| 177 | 179 | ||
| 178 | console.touch_values[index] = TransformToTouch(callback); | 180 | console.touch_values[index] = TransformToTouch(callback); |
| 179 | 181 | ||
| 180 | if (is_configuring) { | 182 | if (is_configuring) { |
| 183 | lock.unlock(); | ||
| 181 | TriggerOnChange(ConsoleTriggerType::Touch); | 184 | TriggerOnChange(ConsoleTriggerType::Touch); |
| 182 | return; | 185 | return; |
| 183 | } | 186 | } |
| @@ -189,26 +192,32 @@ void EmulatedConsole::SetTouch(const Common::Input::CallbackStatus& callback, st | |||
| 189 | .pressed = console.touch_values[index].pressed.value, | 192 | .pressed = console.touch_values[index].pressed.value, |
| 190 | }; | 193 | }; |
| 191 | 194 | ||
| 195 | lock.unlock(); | ||
| 192 | TriggerOnChange(ConsoleTriggerType::Touch); | 196 | TriggerOnChange(ConsoleTriggerType::Touch); |
| 193 | } | 197 | } |
| 194 | 198 | ||
| 195 | ConsoleMotionValues EmulatedConsole::GetMotionValues() const { | 199 | ConsoleMotionValues EmulatedConsole::GetMotionValues() const { |
| 200 | std::lock_guard lock{mutex}; | ||
| 196 | return console.motion_values; | 201 | return console.motion_values; |
| 197 | } | 202 | } |
| 198 | 203 | ||
| 199 | TouchValues EmulatedConsole::GetTouchValues() const { | 204 | TouchValues EmulatedConsole::GetTouchValues() const { |
| 205 | std::lock_guard lock{mutex}; | ||
| 200 | return console.touch_values; | 206 | return console.touch_values; |
| 201 | } | 207 | } |
| 202 | 208 | ||
| 203 | ConsoleMotion EmulatedConsole::GetMotion() const { | 209 | ConsoleMotion EmulatedConsole::GetMotion() const { |
| 210 | std::lock_guard lock{mutex}; | ||
| 204 | return console.motion_state; | 211 | return console.motion_state; |
| 205 | } | 212 | } |
| 206 | 213 | ||
| 207 | TouchFingerState EmulatedConsole::GetTouch() const { | 214 | TouchFingerState EmulatedConsole::GetTouch() const { |
| 215 | std::lock_guard lock{mutex}; | ||
| 208 | return console.touch_state; | 216 | return console.touch_state; |
| 209 | } | 217 | } |
| 210 | 218 | ||
| 211 | void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) { | 219 | void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) { |
| 220 | std::lock_guard lock{callback_mutex}; | ||
| 212 | for (const auto& poller_pair : callback_list) { | 221 | for (const auto& poller_pair : callback_list) { |
| 213 | const ConsoleUpdateCallback& poller = poller_pair.second; | 222 | const ConsoleUpdateCallback& poller = poller_pair.second; |
| 214 | if (poller.on_change) { | 223 | if (poller.on_change) { |
| @@ -218,13 +227,13 @@ void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) { | |||
| 218 | } | 227 | } |
| 219 | 228 | ||
| 220 | int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) { | 229 | int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) { |
| 221 | std::lock_guard lock{mutex}; | 230 | std::lock_guard lock{callback_mutex}; |
| 222 | callback_list.insert_or_assign(last_callback_key, update_callback); | 231 | callback_list.insert_or_assign(last_callback_key, update_callback); |
| 223 | return last_callback_key++; | 232 | return last_callback_key++; |
| 224 | } | 233 | } |
| 225 | 234 | ||
| 226 | void EmulatedConsole::DeleteCallback(int key) { | 235 | void EmulatedConsole::DeleteCallback(int key) { |
| 227 | std::lock_guard lock{mutex}; | 236 | std::lock_guard lock{callback_mutex}; |
| 228 | const auto& iterator = callback_list.find(key); | 237 | const auto& iterator = callback_list.find(key); |
| 229 | if (iterator == callback_list.end()) { | 238 | if (iterator == callback_list.end()) { |
| 230 | LOG_ERROR(Input, "Tried to delete non-existent callback {}", key); | 239 | LOG_ERROR(Input, "Tried to delete non-existent callback {}", key); |