InputCommon: Make Wiimote rumble variable thread safe

This commit is contained in:
Filoppi
2021-05-10 22:44:17 +03:00
parent 08f8c27927
commit a77e3b4a9b
2 changed files with 6 additions and 4 deletions

View File

@ -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();