diff options
| author | 2021-06-22 22:19:34 -0400 | |
|---|---|---|
| committer | 2021-06-22 22:19:34 -0400 | |
| commit | 95b4c78b07434f0b668b1168bf859434cae37a6c (patch) | |
| tree | f2ab7bc1d40ae6c0d767506a1d147c3ef1a62744 /src | |
| parent | Merge pull request #6510 from ReinUsesLisp/npad-data-race (diff) | |
| parent | input_common/mouse_input: Fix data race (diff) | |
| download | yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.gz yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.xz yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.zip | |
Merge pull request #6509 from ReinUsesLisp/mouse-datarace
input_common/mouse_input: Fix data race
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 16 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.h | 6 |
2 files changed, 10 insertions, 12 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index a335e6da1..3b052ffb2 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp | |||
| @@ -2,25 +2,23 @@ | |||
| 2 | // Licensed under GPLv2+ | 2 | // Licensed under GPLv2+ |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <stop_token> | ||
| 6 | #include <thread> | ||
| 7 | |||
| 5 | #include "common/settings.h" | 8 | #include "common/settings.h" |
| 6 | #include "input_common/mouse/mouse_input.h" | 9 | #include "input_common/mouse/mouse_input.h" |
| 7 | 10 | ||
| 8 | namespace MouseInput { | 11 | namespace MouseInput { |
| 9 | 12 | ||
| 10 | Mouse::Mouse() { | 13 | Mouse::Mouse() { |
| 11 | update_thread = std::thread(&Mouse::UpdateThread, this); | 14 | update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); |
| 12 | } | 15 | } |
| 13 | 16 | ||
| 14 | Mouse::~Mouse() { | 17 | Mouse::~Mouse() = default; |
| 15 | update_thread_running = false; | ||
| 16 | if (update_thread.joinable()) { | ||
| 17 | update_thread.join(); | ||
| 18 | } | ||
| 19 | } | ||
| 20 | 18 | ||
| 21 | void Mouse::UpdateThread() { | 19 | void Mouse::UpdateThread(std::stop_token stop_token) { |
| 22 | constexpr int update_time = 10; | 20 | constexpr int update_time = 10; |
| 23 | while (update_thread_running) { | 21 | while (!stop_token.stop_requested()) { |
| 24 | for (MouseInfo& info : mouse_info) { | 22 | for (MouseInfo& info : mouse_info) { |
| 25 | const Common::Vec3f angular_direction{ | 23 | const Common::Vec3f angular_direction{ |
| 26 | -info.tilt_direction.y, | 24 | -info.tilt_direction.y, |
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 5a971ad67..c8bae99c1 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <stop_token> | ||
| 9 | #include <thread> | 10 | #include <thread> |
| 10 | 11 | ||
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| @@ -85,7 +86,7 @@ public: | |||
| 85 | [[nodiscard]] const MouseData& GetMouseState(std::size_t button) const; | 86 | [[nodiscard]] const MouseData& GetMouseState(std::size_t button) const; |
| 86 | 87 | ||
| 87 | private: | 88 | private: |
| 88 | void UpdateThread(); | 89 | void UpdateThread(std::stop_token stop_token); |
| 89 | void UpdateYuzuSettings(); | 90 | void UpdateYuzuSettings(); |
| 90 | void StopPanning(); | 91 | void StopPanning(); |
| 91 | 92 | ||
| @@ -105,12 +106,11 @@ private: | |||
| 105 | u16 buttons{}; | 106 | u16 buttons{}; |
| 106 | u16 toggle_buttons{}; | 107 | u16 toggle_buttons{}; |
| 107 | u16 lock_buttons{}; | 108 | u16 lock_buttons{}; |
| 108 | std::thread update_thread; | 109 | std::jthread update_thread; |
| 109 | MouseButton last_button{MouseButton::Undefined}; | 110 | MouseButton last_button{MouseButton::Undefined}; |
| 110 | std::array<MouseInfo, 7> mouse_info; | 111 | std::array<MouseInfo, 7> mouse_info; |
| 111 | Common::SPSCQueue<MouseStatus> mouse_queue; | 112 | Common::SPSCQueue<MouseStatus> mouse_queue; |
| 112 | bool configuring{false}; | 113 | bool configuring{false}; |
| 113 | bool update_thread_running{true}; | ||
| 114 | int mouse_panning_timout{}; | 114 | int mouse_panning_timout{}; |
| 115 | }; | 115 | }; |
| 116 | } // namespace MouseInput | 116 | } // namespace MouseInput |