diff options
author | Mai M <mathew1800@gmail.com> | 2021-06-22 22:19:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-22 22:19:34 -0400 |
commit | 95b4c78b07434f0b668b1168bf859434cae37a6c (patch) | |
tree | f2ab7bc1d40ae6c0d767506a1d147c3ef1a62744 /src/input_common/mouse/mouse_input.cpp | |
parent | 4ec7d79174e5383941767ace57888168c5f6b017 (diff) | |
parent | 0a39163a90de377843d4726154a0247caa928fa1 (diff) |
Merge pull request #6509 from ReinUsesLisp/mouse-datarace
input_common/mouse_input: Fix data race
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
-rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 16 |
1 files changed, 7 insertions, 9 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, |