Fix Wiimote thread wakeup on externally-triggered destroy.
This commit is contained in:
parent
dc87b6d431
commit
8992f58720
|
@ -503,11 +503,14 @@ bool Wiimote::Connect()
|
||||||
|
|
||||||
void Wiimote::StartThread()
|
void Wiimote::StartThread()
|
||||||
{
|
{
|
||||||
|
m_run_thread = true;
|
||||||
m_wiimote_thread = std::thread(std::mem_fun(&Wiimote::ThreadFunc), this);
|
m_wiimote_thread = std::thread(std::mem_fun(&Wiimote::ThreadFunc), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wiimote::StopThread()
|
void Wiimote::StopThread()
|
||||||
{
|
{
|
||||||
|
m_run_thread = false;
|
||||||
|
IOWakeup();
|
||||||
if (m_wiimote_thread.joinable())
|
if (m_wiimote_thread.joinable())
|
||||||
m_wiimote_thread.join();
|
m_wiimote_thread.join();
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
@ -554,7 +557,7 @@ void Wiimote::ThreadFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
while (IsConnected())
|
while (IsConnected() && m_run_thread)
|
||||||
{
|
{
|
||||||
if (m_need_prepare)
|
if (m_need_prepare)
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,8 +113,12 @@ private:
|
||||||
bool m_rumble_state;
|
bool m_rumble_state;
|
||||||
|
|
||||||
std::thread m_wiimote_thread;
|
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;
|
volatile bool m_need_prepare;
|
||||||
|
// Whether the thread has finished ConnectInternal.
|
||||||
|
volatile bool m_thread_ready;
|
||||||
std::mutex m_thread_ready_mutex;
|
std::mutex m_thread_ready_mutex;
|
||||||
std::condition_variable m_thread_ready_cond;
|
std::condition_variable m_thread_ready_cond;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue