mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-05 06:21:26 +12:00
input: make pad_thread a named_thread
This commit is contained in:
parent
a74156fe5b
commit
29256df5b1
4 changed files with 18 additions and 23 deletions
|
@ -37,5 +37,5 @@ struct progress_dialog_server
|
||||||
void operator()();
|
void operator()();
|
||||||
~progress_dialog_server();
|
~progress_dialog_server();
|
||||||
|
|
||||||
static auto constexpr thread_name = "Progress Dialog Server"sv;
|
static constexpr auto thread_name = "Progress Dialog Server"sv;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include "Emu/Io/Null/NullPadHandler.h"
|
#include "Emu/Io/Null/NullPadHandler.h"
|
||||||
#include "Emu/Io/PadHandler.h"
|
#include "Emu/Io/PadHandler.h"
|
||||||
#include "Emu/Io/pad_config.h"
|
#include "Emu/Io/pad_config.h"
|
||||||
|
#include "Emu/System.h"
|
||||||
|
#include "Utilities/Thread.h"
|
||||||
|
|
||||||
LOG_CHANNEL(input_log, "Input");
|
LOG_CHANNEL(input_log, "Input");
|
||||||
|
|
||||||
|
@ -24,7 +26,6 @@ namespace pad
|
||||||
std::string g_title_id;
|
std::string g_title_id;
|
||||||
atomic_t<bool> g_reset{false};
|
atomic_t<bool> g_reset{false};
|
||||||
atomic_t<bool> g_enabled{true};
|
atomic_t<bool> g_enabled{true};
|
||||||
atomic_t<bool> g_active{false};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pad_setting
|
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_thread::pad_thread(void *_curthread, void *_curwindow, std::string_view title_id) : curthread(_curthread), curwindow(_curwindow)
|
||||||
{
|
{
|
||||||
pad::g_title_id = title_id;
|
pad::g_title_id = title_id;
|
||||||
Init();
|
|
||||||
|
|
||||||
thread = std::make_shared<std::thread>(&pad_thread::ThreadFunc, this);
|
|
||||||
pad::g_current = this;
|
pad::g_current = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
pad_thread::~pad_thread()
|
pad_thread::~pad_thread()
|
||||||
{
|
{
|
||||||
pad::g_current = nullptr;
|
pad::g_current = nullptr;
|
||||||
pad::g_active = false;
|
|
||||||
thread->join();
|
|
||||||
|
|
||||||
handlers.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pad_thread::Init()
|
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;
|
pad::g_reset = true;
|
||||||
while (pad::g_active)
|
|
||||||
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +271,7 @@ void pad_thread::ThreadFunc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::this_thread::sleep_for(1ms);
|
thread_ctrl::wait_for(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include "Utilities/mutex.h"
|
#include "Utilities/mutex.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -23,10 +22,11 @@ public:
|
||||||
pad_thread& operator=(const pad_thread&) = delete;
|
pad_thread& operator=(const pad_thread&) = delete;
|
||||||
~pad_thread();
|
~pad_thread();
|
||||||
|
|
||||||
|
void operator()();
|
||||||
|
|
||||||
PadInfo& GetInfo() { return m_info; }
|
PadInfo& GetInfo() { return m_info; }
|
||||||
auto& GetPads() { return m_pads; }
|
auto& GetPads() { return m_pads; }
|
||||||
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
|
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
|
||||||
void Init();
|
|
||||||
void SetIntercepted(bool intercepted);
|
void SetIntercepted(bool intercepted);
|
||||||
|
|
||||||
s32 AddLddPad();
|
s32 AddLddPad();
|
||||||
|
@ -35,9 +35,11 @@ public:
|
||||||
static std::shared_ptr<PadHandlerBase> GetHandler(pad_handler type);
|
static std::shared_ptr<PadHandlerBase> GetHandler(pad_handler type);
|
||||||
static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler);
|
static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler);
|
||||||
|
|
||||||
|
static auto constexpr thread_name = "Pad Thread"sv;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void Init();
|
||||||
void InitLddPad(u32 handle);
|
void InitLddPad(u32 handle);
|
||||||
void ThreadFunc();
|
|
||||||
|
|
||||||
// List of all handlers
|
// List of all handlers
|
||||||
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
|
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
|
||||||
|
@ -49,8 +51,6 @@ protected:
|
||||||
PadInfo m_info{ 0, 0, false };
|
PadInfo m_info{ 0, 0, false };
|
||||||
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
|
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
|
||||||
|
|
||||||
std::shared_ptr<std::thread> thread;
|
|
||||||
|
|
||||||
u32 num_ldd_pad = 0;
|
u32 num_ldd_pad = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ namespace pad
|
||||||
extern std::string g_title_id;
|
extern std::string g_title_id;
|
||||||
extern atomic_t<bool> g_enabled;
|
extern atomic_t<bool> g_enabled;
|
||||||
extern atomic_t<bool> g_reset;
|
extern atomic_t<bool> g_reset;
|
||||||
extern atomic_t<bool> g_active;
|
|
||||||
|
|
||||||
static inline class pad_thread* get_current_handler(bool relaxed = false)
|
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)
|
static inline void reset(std::string_view title_id)
|
||||||
{
|
{
|
||||||
g_title_id = title_id;
|
g_title_id = title_id;
|
||||||
g_reset = g_active.load();
|
g_reset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void SetIntercepted(bool intercepted)
|
static inline void SetIntercepted(bool intercepted)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "util/logs.hpp"
|
#include "util/logs.hpp"
|
||||||
#include "util/sysinfo.hpp"
|
#include "util/sysinfo.hpp"
|
||||||
|
|
||||||
|
#include "Utilities/Thread.h"
|
||||||
#include "Input/pad_thread.h"
|
#include "Input/pad_thread.h"
|
||||||
#include "Emu/System.h"
|
#include "Emu/System.h"
|
||||||
#include "Emu/system_config.h"
|
#include "Emu/system_config.h"
|
||||||
|
@ -99,7 +100,7 @@ EmuCallbacks main_application::CreateCallbacks()
|
||||||
|
|
||||||
callbacks.init_pad_handler = [this](std::string_view title_id)
|
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>
|
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue