Compare commits

..

1 Commits

Author SHA1 Message Date
Rodrigo Locatti
c9c8537643 core: Make is_powered_on atomic
Fixes potential data races when shutting down.
2021-06-22 04:33:07 -03:00
3 changed files with 15 additions and 12 deletions

View File

@@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <array>
#include <atomic>
#include <memory>
#include <utility>
@@ -377,7 +378,7 @@ struct System::Impl {
std::unique_ptr<Core::DeviceMemory> device_memory;
Core::Memory::Memory memory;
CpuManager cpu_manager;
bool is_powered_on = false;
std::atomic_bool is_powered_on{};
bool exit_lock = false;
Reporter reporter;
@@ -463,7 +464,7 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
}
bool System::IsPoweredOn() const {
return impl->is_powered_on;
return impl->is_powered_on.load(std::memory_order::relaxed);
}
void System::PrepareReschedule() {

View File

@@ -2,23 +2,25 @@
// 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::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); });
update_thread = std::thread(&Mouse::UpdateThread, this);
}
Mouse::~Mouse() = default;
Mouse::~Mouse() {
update_thread_running = false;
if (update_thread.joinable()) {
update_thread.join();
}
}
void Mouse::UpdateThread(std::stop_token stop_token) {
void Mouse::UpdateThread() {
constexpr int update_time = 10;
while (!stop_token.stop_requested()) {
while (update_thread_running) {
for (MouseInfo& info : mouse_info) {
const Common::Vec3f angular_direction{
-info.tilt_direction.y,

View File

@@ -6,7 +6,6 @@
#include <array>
#include <mutex>
#include <stop_token>
#include <thread>
#include "common/common_types.h"
@@ -86,7 +85,7 @@ public:
[[nodiscard]] const MouseData& GetMouseState(std::size_t button) const;
private:
void UpdateThread(std::stop_token stop_token);
void UpdateThread();
void UpdateYuzuSettings();
void StopPanning();
@@ -106,11 +105,12 @@ private:
u16 buttons{};
u16 toggle_buttons{};
u16 lock_buttons{};
std::jthread update_thread;
std::thread 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