diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index 6cb9521981..77f84449be 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -503,11 +503,14 @@ bool Wiimote::Connect() void Wiimote::StartThread() { + m_run_thread = true; m_wiimote_thread = std::thread(std::mem_fun(&Wiimote::ThreadFunc), this); } void Wiimote::StopThread() { + m_run_thread = false; + IOWakeup(); if (m_wiimote_thread.joinable()) m_wiimote_thread.join(); #if defined(__APPLE__) @@ -554,7 +557,7 @@ void Wiimote::ThreadFunc() } // main loop - while (IsConnected()) + while (IsConnected() && m_run_thread) { if (m_need_prepare) { diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index 314fb2e83c..fa94303a66 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -113,8 +113,12 @@ private: bool m_rumble_state; std::thread m_wiimote_thread; - volatile bool m_thread_ready; + // Whether to keep running the thread. + volatile bool m_run_thread; + // Whether to call PrepareOnThread. volatile bool m_need_prepare; + // Whether the thread has finished ConnectInternal. + volatile bool m_thread_ready; std::mutex m_thread_ready_mutex; std::condition_variable m_thread_ready_cond;