Skip to content

Commit

Permalink
WiimoteReal: Use Event for timing scans
Browse files Browse the repository at this point in the history
This makes exiting instant since it removes a random 0-500ms delay.
  • Loading branch information
leoetlino committed Jul 7, 2016
1 parent 37a9932 commit 481d7aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ void WiimoteScanner::StartScanning(bool scan_only_once)
m_run_thread.store(true);
m_scan_thread = std::thread(&WiimoteScanner::ThreadFunc, this);
}
m_scan_event.Set();
}

void WiimoteScanner::StopScanning(bool stop_thread)
Expand All @@ -457,6 +458,7 @@ void WiimoteScanner::StopScanning(bool stop_thread)
if (!stop_thread)
return;
m_run_thread.store(false);
m_scan_event.Set();
if (m_scan_thread.joinable())
{
m_scan_thread.join();
Expand All @@ -480,11 +482,9 @@ void WiimoteScanner::ThreadFunc()

while (m_run_thread.load())
{
m_scan_event.WaitFor(std::chrono::milliseconds(500));
if (!m_should_scan.load())
{
Common::SleepCurrentThread(500);
continue;
}
m_should_scan.store(!m_should_scan_only_once.load());

std::vector<Wiimote*> found_wiimotes;
Expand Down Expand Up @@ -512,9 +512,6 @@ void WiimoteScanner::ThreadFunc()

if (m_want_bb.load() && found_board)
TryToConnectBalanceBoard(found_board);

// std::this_thread::yield();
Common::SleepCurrentThread(500);
}

NOTICE_LOG(WIIMOTE, "Wiimote scanning thread has stopped.");
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "Common/Common.h"
#include "Common/Event.h"
#include "Common/FifoQueue.h"
#include "Common/NonCopyable.h"
#include "Core/HW/Wiimote.h"
Expand Down Expand Up @@ -136,6 +137,7 @@ class WiimoteScanner

std::thread m_scan_thread;

Common::Event m_scan_event;
std::atomic<bool> m_run_thread{false};
std::atomic<bool> m_should_scan{false};
std::atomic<bool> m_should_scan_only_once{false}; // for the Refresh button
Expand Down

0 comments on commit 481d7aa

Please sign in to comment.