From 012939d1278db9565499f2dc33773b49d86f6058 Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Wed, 5 Jan 2011 01:45:36 +0000 Subject: [PATCH] After removing the input queueing in IOdarwin.mm I was still seeing the occasional HLE wiimote disconnection, although nowhere it was at near the level before both the recent wiiuse integration and adding the queue in the first place. The callback-based bluetooth input method on OS X really requires that packets be accepted immediately and the 1ms polling done by the wiimote worker threads isn't quite good enough. So just play along with the native OS X model and send the packet up our stack directly from the callback. With our current API, this is kind of a layering violation, but it seems less messy than either putting back internal queueing in IOdarwin.mm or adding the platform support for higher-frequency polling than what usleep(3) offers. Perhaps we should just change our own API to a callback model. While this makes no real difference right now, it would make it a fair bit cleaner to accept new wiimotes at any time instead of having to click Refresh, although with the recent realmote changes, that feature can probably just be hacked in by looping around FindWiimotes(). For other platforms having problems with HLE disconnections caused by dropped bluetooth packets, as a first stop I would suggest trying to do more than just one wiimote->Read() per iteration in the thread. This change also conveniently sidesteps another new IOdarwin.mm bug where the discovery and I/O code would clash during a refresh because they use the same default CFRunLoop, so if we switch back to using a run loop for I/O, must remember to create a separate one. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6743 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm | 9 ++------- Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 2 ++ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm index 93eeb03357..dc01e7841e 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/Src/HW/WiimoteReal/IOdarwin.mm @@ -70,7 +70,7 @@ extern "C" OSErr UpdateSystemActivity(UInt8 activity); memcpy(wm->input, data, length); wm->inputlen = length; - CFRunLoopStop(CFRunLoopGetCurrent()); + (void)wm->Read(); (void)UpdateSystemActivity(1); } @@ -125,7 +125,7 @@ int FindWiimotes(Wiimote **wm, int max_wiimotes) } sbt = [[SearchBT alloc] init]; - sbt->maxDevices = max_wiimotes; + sbt->maxDevices = max_wiimotes - found_wiimotes; bti = [[IOBluetoothDeviceInquiry alloc] init]; [bti setDelegate: sbt]; [bti setInquiryLength: 5]; @@ -226,11 +226,6 @@ int Wiimote::IORead(unsigned char *buf) if (!IsConnected()) return 0; - if (inputlen == 0) { - CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true); - return 0; - } - bytes = inputlen; memcpy(buf, input, bytes); inputlen = 0; diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index b75bd0cd6b..f08d50c088 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -543,8 +543,10 @@ THREAD_RETURN WiimoteThreadFunc(void* arg) // hopefully this is alright while (wiimote->Write()) {} +#ifndef __APPLE__ // sleep if there was nothing to read if (false == wiimote->Read()) +#endif Common::SleepCurrentThread(1); }