diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/input_common/analog_from_button.cpp | 14 |
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 5 | #include <chrono> | 6 | #include <chrono> |
| 6 | #include <cmath> | 7 | #include <cmath> |
| 7 | #include <thread> | 8 | #include <thread> |
| @@ -20,13 +21,16 @@ public: | |||
| 20 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), | 21 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), |
| 21 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), | 22 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), |
| 22 | modifier_angle(modifier_angle_) { | 23 | modifier_angle(modifier_angle_) { |
| 24 | update_thread_running.store(true); | ||
| 23 | update_thread = std::thread(&Analog::UpdateStatus, this); | 25 | update_thread = std::thread(&Analog::UpdateStatus, this); |
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | ~Analog() override { | 28 | ~Analog() override { |
| 27 | update_thread_running = false; | 29 | if (update_thread_running.load()) { |
| 28 | if (update_thread.joinable()) { | 30 | update_thread_running.store(false); |
| 29 | update_thread.join(); | 31 | if (update_thread.joinable()) { |
| 32 | update_thread.join(); | ||
| 33 | } | ||
| 30 | } | 34 | } |
| 31 | } | 35 | } |
| 32 | 36 | ||
| @@ -58,7 +62,7 @@ public: | |||
| 58 | } | 62 | } |
| 59 | 63 | ||
| 60 | void UpdateStatus() { | 64 | void UpdateStatus() { |
| 61 | while (update_thread_running) { | 65 | while (update_thread_running.load()) { |
| 62 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | 66 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; |
| 63 | 67 | ||
| 64 | bool r = right->GetStatus(); | 68 | bool r = right->GetStatus(); |
| @@ -160,7 +164,7 @@ private: | |||
| 160 | float angle{}; | 164 | float angle{}; |
| 161 | float amplitude{}; | 165 | float amplitude{}; |
| 162 | std::thread update_thread; | 166 | std::thread update_thread; |
| 163 | bool update_thread_running{true}; | 167 | std::atomic<bool> update_thread_running{}; |
| 164 | }; | 168 | }; |
| 165 | 169 | ||
| 166 | std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) { | 170 | std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) { |