From 0fb7f65e04f966f9eef1b8dfcb7d8d8ebec834ae Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 11 Feb 2013 15:58:23 -0600 Subject: [PATCH] Problems on Windows? Just SLEEP twice as long! --- Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp | 6 +++++- Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp index d6bc5dd28b..3052f4b737 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp @@ -75,6 +75,7 @@ HINSTANCE bthprops_lib = NULL; static int initialized = 0; +std::mutex g_connected_devices_lock; static std::unordered_set g_connected_devices; inline void init_lib() @@ -182,7 +183,7 @@ std::vector WiimoteScanner::FindWiimotes() // Hacks... if (attached_some) - SLEEP(1000); + SLEEP(2000); GUID device_id; HDEVINFO device_info; @@ -253,6 +254,8 @@ bool WiimoteScanner::IsReady() const // Connect to a wiimote with a known device path. bool Wiimote::Connect() { + std::lock_guard lk(g_connected_devices_lock); + // This is where we disallow connecting to the same device twice if (g_connected_devices.count(devicepath)) return false; @@ -303,6 +306,7 @@ bool Wiimote::Connect() void Wiimote::Disconnect() { + std::lock_guard lk(g_connected_devices_lock); g_connected_devices.erase(devicepath); CloseHandle(dev_handle); diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index 55fc552abd..793a13ceb0 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -64,8 +64,6 @@ public: // connecting and disconnecting from physical devices // (using address inserted by FindWiimotes) - - // FYI, Connect/Disconnect are not thread safe even between unique objects (on windows) bool Connect(); void Disconnect();