Skip to content

Commit

Permalink
Fix Wiimote thread wakeup on externally-triggered destroy.
Browse files Browse the repository at this point in the history
  • Loading branch information
comex committed Sep 4, 2013
1 parent dc87b6d commit 8992f58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp
Expand Up @@ -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__)
Expand Down Expand Up @@ -554,7 +557,7 @@ void Wiimote::ThreadFunc()
}

// main loop
while (IsConnected())
while (IsConnected() && m_run_thread)
{
if (m_need_prepare)
{
Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h
Expand Up @@ -113,8 +113,12 @@ friend class WiimoteEmu::Wiimote;
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;

Expand Down

0 comments on commit 8992f58

Please sign in to comment.