summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorFiloppi <filippotarpini@hotmail.it>2021-05-10 22:44:17 +0300
committerFiloppi <filippotarpini@hotmail.it>2021-06-07 11:48:30 +0300
commita77e3b4a9bc557ac00b63c13abdb4074069e9a7d (patch)
treefeefc3ebdeb680efae638d41e59877be2939a3c2 /Source/Core/InputCommon/ControllerInterface
parent08f8c279274455ecf16a3a447378f37062408c9b (diff)
InputCommon: Make Wiimote rumble variable thread safe
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp7
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h3
2 files changed, 6 insertions, 4 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp
index d68b0441a6..82e2cfedda 100644
--- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp
@@ -82,14 +82,14 @@ using UndetectableSignedAnalogInput = SignedInput<false>;
class Motor final : public Core::Device::Output
{
public:
- Motor(ControlState* value) : m_value(*value) {}
+ Motor(std::atomic<ControlState>* value) : m_value(*value) {}
std::string GetName() const override { return "Motor"; }
void SetState(ControlState state) override { m_value = state; }
private:
- ControlState& m_value;
+ std::atomic<ControlState>& m_value;
};
template <typename T>
@@ -1377,7 +1377,8 @@ void Device::UpdateRumble()
{
static constexpr auto rumble_period = std::chrono::milliseconds(100);
- const auto on_time = std::chrono::duration_cast<Clock::duration>(rumble_period * m_rumble_level);
+ const auto on_time =
+ std::chrono::duration_cast<Clock::duration>(rumble_period * m_rumble_level.load());
const auto off_time = rumble_period - on_time;
const auto now = Clock::now();
diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h
index b6c96d0238..4d93584a67 100644
--- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h
+++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h
@@ -5,6 +5,7 @@
#pragma once
#include <array>
+#include <atomic>
#include <chrono>
#include <memory>
#include <vector>
@@ -262,7 +263,7 @@ private:
bool m_rumble = false;
// For pulse of rumble motor to simulate multiple levels.
- ControlState m_rumble_level = 0;
+ std::atomic<ControlState> m_rumble_level;
Clock::time_point m_last_rumble_change = Clock::now();
// Assume mode is disabled so one gets set.