Skip to content

Commit 4c788ab

Browse files
committed
Use named_thread in gui_pad_thread
1 parent 3737cc3 commit 4c788ab

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

rpcs3/Input/gui_pad_thread.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#endif
1616
#include "Emu/Io/PadHandler.h"
1717
#include "Emu/system_config.h"
18-
#include "Utilities/Thread.h"
1918
#include "rpcs3qt/gui_settings.h"
2019

2120
#ifdef __linux__
@@ -43,16 +42,16 @@ atomic_t<bool> gui_pad_thread::m_reset = false;
4342

4443
gui_pad_thread::gui_pad_thread()
4544
{
46-
m_thread = std::make_unique<std::thread>(&gui_pad_thread::run, this);
45+
m_thread = std::make_unique<named_thread<std::function<void()>>>("Gui Pad Thread", [this](){ run(); });
4746
}
4847

4948
gui_pad_thread::~gui_pad_thread()
5049
{
51-
m_terminate = true;
52-
53-
if (m_thread && m_thread->joinable())
50+
if (m_thread)
5451
{
55-
m_thread->join();
52+
auto& thread = *m_thread;
53+
thread = thread_state::aborting;
54+
thread();
5655
m_thread.reset();
5756
}
5857

@@ -253,13 +252,11 @@ void gui_pad_thread::InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_p
253252

254253
void gui_pad_thread::run()
255254
{
256-
thread_base::set_name("Gui Pad Thread");
257-
258255
gui_log.notice("gui_pad_thread: Pad thread started");
259256

260257
m_reset = true;
261258

262-
while (!m_terminate)
259+
while (thread_ctrl::state() != thread_state::aborting)
263260
{
264261
if (m_reset && m_reset.exchange(false))
265262
{
@@ -275,20 +272,15 @@ void gui_pad_thread::run()
275272
{
276273
m_handler->process();
277274

278-
if (m_terminate)
275+
if (thread_ctrl::state() == thread_state::aborting)
279276
{
280277
break;
281278
}
282279

283280
process_input();
284281
}
285282

286-
if (m_terminate)
287-
{
288-
break;
289-
}
290-
291-
std::this_thread::sleep_for(10ms);
283+
thread_ctrl::wait_for(10000);
292284
}
293285

294286
gui_log.notice("gui_pad_thread: Pad thread stopped");

rpcs3/Input/gui_pad_thread.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "Emu/Io/pad_config.h"
77
#include "Emu/Io/pad_config_types.h"
88
#include "Utilities/Timer.h"
9-
10-
#include <thread>
9+
#include "Utilities/Thread.h"
1110

1211
class PadHandlerBase;
1312
class gui_settings;
@@ -62,8 +61,7 @@ class gui_pad_thread
6261
std::shared_ptr<PadHandlerBase> m_handler;
6362
std::shared_ptr<Pad> m_pad;
6463

65-
std::unique_ptr<std::thread> m_thread;
66-
atomic_t<bool> m_terminate = false;
64+
std::unique_ptr<named_thread<std::function<void()>>> m_thread;
6765
atomic_t<bool> m_allow_global_input = false;
6866
static atomic_t<bool> m_reset;
6967

0 commit comments

Comments
 (0)