1
0
Fork 1
forked from suyu/suyu

Merge pull request #6509 from ReinUsesLisp/mouse-datarace

input_common/mouse_input: Fix data race
This commit is contained in:
Mai M 2021-06-22 22:19:34 -04:00 committed by GitHub
commit 95b4c78b07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View file

@ -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,

View file

@ -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