1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-26 04:32:35 +01:00

input: make pad_thread a named_thread

This commit is contained in:
Megamouse 2021-09-07 21:56:49 +02:00
parent a74156fe5b
commit 29256df5b1
4 changed files with 18 additions and 23 deletions

View File

@ -37,5 +37,5 @@ struct progress_dialog_server
void operator()();
~progress_dialog_server();
static auto constexpr thread_name = "Progress Dialog Server"sv;
static constexpr auto thread_name = "Progress Dialog Server"sv;
};

View File

@ -14,6 +14,8 @@
#include "Emu/Io/Null/NullPadHandler.h"
#include "Emu/Io/PadHandler.h"
#include "Emu/Io/pad_config.h"
#include "Emu/System.h"
#include "Utilities/Thread.h"
LOG_CHANNEL(input_log, "Input");
@ -24,7 +26,6 @@ namespace pad
std::string g_title_id;
atomic_t<bool> g_reset{false};
atomic_t<bool> g_enabled{true};
atomic_t<bool> g_active{false};
}
struct pad_setting
@ -38,19 +39,12 @@ struct pad_setting
pad_thread::pad_thread(void *_curthread, void *_curwindow, std::string_view title_id) : curthread(_curthread), curwindow(_curwindow)
{
pad::g_title_id = title_id;
Init();
thread = std::make_shared<std::thread>(&pad_thread::ThreadFunc, this);
pad::g_current = this;
}
pad_thread::~pad_thread()
{
pad::g_current = nullptr;
pad::g_active = false;
thread->join();
handlers.clear();
}
void pad_thread::Init()
@ -214,14 +208,15 @@ void pad_thread::SetIntercepted(bool intercepted)
}
}
void pad_thread::ThreadFunc()
void pad_thread::operator()()
{
pad::g_active = true;
while (pad::g_active)
pad::g_reset = true;
while (thread_ctrl::state() != thread_state::aborting)
{
if (!pad::g_enabled)
if (!pad::g_enabled || Emu.IsPaused())
{
std::this_thread::sleep_for(1ms);
thread_ctrl::wait_for(10000);
continue;
}
@ -276,7 +271,7 @@ void pad_thread::ThreadFunc()
}
}
std::this_thread::sleep_for(1ms);
thread_ctrl::wait_for(1000);
}
}

View File

@ -8,7 +8,6 @@
#include "Utilities/mutex.h"
#include <map>
#include <thread>
#include <mutex>
#include <string_view>
#include <string>
@ -23,10 +22,11 @@ public:
pad_thread& operator=(const pad_thread&) = delete;
~pad_thread();
void operator()();
PadInfo& GetInfo() { return m_info; }
auto& GetPads() { return m_pads; }
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
void Init();
void SetIntercepted(bool intercepted);
s32 AddLddPad();
@ -35,9 +35,11 @@ public:
static std::shared_ptr<PadHandlerBase> GetHandler(pad_handler type);
static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler);
static auto constexpr thread_name = "Pad Thread"sv;
protected:
void Init();
void InitLddPad(u32 handle);
void ThreadFunc();
// List of all handlers
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
@ -49,8 +51,6 @@ protected:
PadInfo m_info{ 0, 0, false };
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
std::shared_ptr<std::thread> thread;
u32 num_ldd_pad = 0;
};
@ -61,7 +61,6 @@ namespace pad
extern std::string g_title_id;
extern atomic_t<bool> g_enabled;
extern atomic_t<bool> g_reset;
extern atomic_t<bool> g_active;
static inline class pad_thread* get_current_handler(bool relaxed = false)
{
@ -81,7 +80,7 @@ namespace pad
static inline void reset(std::string_view title_id)
{
g_title_id = title_id;
g_reset = g_active.load();
g_reset = true;
}
static inline void SetIntercepted(bool intercepted)

View File

@ -4,6 +4,7 @@
#include "util/logs.hpp"
#include "util/sysinfo.hpp"
#include "Utilities/Thread.h"
#include "Input/pad_thread.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
@ -99,7 +100,7 @@ EmuCallbacks main_application::CreateCallbacks()
callbacks.init_pad_handler = [this](std::string_view title_id)
{
g_fxo->init<pad_thread>(get_thread(), m_game_window, title_id);
g_fxo->init<named_thread<pad_thread>>(get_thread(), m_game_window, title_id);
};
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>