summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMai M <mathew1800@gmail.com>2021-06-23 04:19:34 +0200
committerGitHub <noreply@github.com>2021-06-23 04:19:34 +0200
commit95b4c78b07434f0b668b1168bf859434cae37a6c (patch)
treef2ab7bc1d40ae6c0d767506a1d147c3ef1a62744 /src
parentMerge pull request #6510 from ReinUsesLisp/npad-data-race (diff)
parentinput_common/mouse_input: Fix data race (diff)
downloadyuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar
yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.gz
yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.bz2
yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.lz
yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.xz
yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.tar.zst
yuzu-95b4c78b07434f0b668b1168bf859434cae37a6c.zip
Diffstat (limited to '')
-rw-r--r--src/input_common/mouse/mouse_input.cpp16
-rw-r--r--src/input_common/mouse/mouse_input.h6
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 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include <stop_token>
+#include <thread>
+
#include "common/settings.h"
#include "input_common/mouse/mouse_input.h"
namespace MouseInput {
Mouse::Mouse() {
- update_thread = std::thread(&Mouse::UpdateThread, this);
+ update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); });
}
-Mouse::~Mouse() {
- update_thread_running = false;
- if (update_thread.joinable()) {
- update_thread.join();
- }
-}
+Mouse::~Mouse() = default;
-void Mouse::UpdateThread() {
+void Mouse::UpdateThread(std::stop_token stop_token) {
constexpr int update_time = 10;
- while (update_thread_running) {
+ while (!stop_token.stop_requested()) {
for (MouseInfo& info : mouse_info) {
const Common::Vec3f angular_direction{
-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 @@
#include <array>
#include <mutex>
+#include <stop_token>
#include <thread>
#include "common/common_types.h"
@@ -85,7 +86,7 @@ public:
[[nodiscard]] const MouseData& GetMouseState(std::size_t button) const;
private:
- void UpdateThread();
+ void UpdateThread(std::stop_token stop_token);
void UpdateYuzuSettings();
void StopPanning();
@@ -105,12 +106,11 @@ private:
u16 buttons{};
u16 toggle_buttons{};
u16 lock_buttons{};
- std::thread update_thread;
+ std::jthread update_thread;
MouseButton last_button{MouseButton::Undefined};
std::array<MouseInfo, 7> mouse_info;
Common::SPSCQueue<MouseStatus> mouse_queue;
bool configuring{false};
- bool update_thread_running{true};
int mouse_panning_timout{};
};
} // namespace MouseInput