summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-01-30 00:41:22 +0100
committerameerj <52414509+ameerj@users.noreply.github.com>2021-01-30 00:41:22 +0100
commitef8b3623f5759af03a7d35e147a4f890366d440f (patch)
tree3402324ced9241388141f8ea9515bcba1dbed87c /src/input_common
parentMerge pull request #5809 from ogniK5377/FlushAudioOutBuffers (diff)
downloadyuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.tar
yuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.tar.gz
yuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.tar.bz2
yuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.tar.lz
yuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.tar.xz
yuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.tar.zst
yuzu-ef8b3623f5759af03a7d35e147a4f890366d440f.zip
Diffstat (limited to 'src/input_common')
-rwxr-xr-xsrc/input_common/analog_from_button.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp
index 40b516f85..07a0fa4a1 100755
--- a/src/input_common/analog_from_button.cpp
+++ b/src/input_common/analog_from_button.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <atomic>
#include <chrono>
#include <cmath>
#include <thread>
@@ -20,13 +21,16 @@ public:
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
modifier_angle(modifier_angle_) {
+ update_thread_running.store(true);
update_thread = std::thread(&Analog::UpdateStatus, this);
}
~Analog() override {
- update_thread_running = false;
- if (update_thread.joinable()) {
- update_thread.join();
+ if (update_thread_running.load()) {
+ update_thread_running.store(false);
+ if (update_thread.joinable()) {
+ update_thread.join();
+ }
}
}
@@ -58,7 +62,7 @@ public:
}
void UpdateStatus() {
- while (update_thread_running) {
+ while (update_thread_running.load()) {
const float coef = modifier->GetStatus() ? modifier_scale : 1.0f;
bool r = right->GetStatus();
@@ -160,7 +164,7 @@ private:
float angle{};
float amplitude{};
std::thread update_thread;
- bool update_thread_running{true};
+ std::atomic<bool> update_thread_running{};
};
std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) {