Hopefully make real wiimotes on OSX less crashy.

This commit is contained in:
Jordan Woyak 2013-02-08 16:54:48 -06:00
parent 1998da867b
commit 1f1b4a6992
2 changed files with 11 additions and 7 deletions

View File

@ -41,7 +41,10 @@
IOBluetoothDevice *device = [l2capChannel getDevice]; IOBluetoothDevice *device = [l2capChannel getDevice];
WiimoteReal::Wiimote *wm = NULL; WiimoteReal::Wiimote *wm = NULL;
for (int i = 0; i < MAX_WIIMOTES; i++) { std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
for (int i = 0; i < MAX_WIIMOTES; i++)
{
if (WiimoteReal::g_wiimotes[i] == NULL) if (WiimoteReal::g_wiimotes[i] == NULL)
continue; continue;
if ([device isEqual: WiimoteReal::g_wiimotes[i]->btd] == TRUE) if ([device isEqual: WiimoteReal::g_wiimotes[i]->btd] == TRUE)
@ -78,7 +81,10 @@
IOBluetoothDevice *device = [l2capChannel getDevice]; IOBluetoothDevice *device = [l2capChannel getDevice];
WiimoteReal::Wiimote *wm = NULL; WiimoteReal::Wiimote *wm = NULL;
for (int i = 0; i < MAX_WIIMOTES; i++) { std::lock_guard<std::recursive_mutex> lk(g_refresh_lock);
for (int i = 0; i < MAX_WIIMOTES; i++)
{
if (WiimoteReal::g_wiimotes[i] == NULL) if (WiimoteReal::g_wiimotes[i] == NULL)
continue; continue;
if ([device isEqual: WiimoteReal::g_wiimotes[i]->btd] == TRUE) if ([device isEqual: WiimoteReal::g_wiimotes[i]->btd] == TRUE)
@ -237,8 +243,6 @@ int Wiimote::IORead(unsigned char *buf)
if (!IsConnected()) if (!IsConnected())
return 0; return 0;
// TODO: race conditions here, yo
bytes = inputlen; bytes = inputlen;
memcpy(buf, input, bytes); memcpy(buf, input, bytes);
inputlen = 0; inputlen = 0;

View File

@ -360,13 +360,13 @@ void Wiimote::ThreadFunc()
while (m_run_thread && IsConnected()) while (m_run_thread && IsConnected())
{ {
#ifdef __APPLE__ #ifdef __APPLE__
while (Write()) {} // Reading happens elsewhere on OSX
Common::SleepCurrentThread(1); bool const did_something = Write();
#else #else
bool const did_something = Write() || Read(); bool const did_something = Write() || Read();
#endif
if (!did_something) if (!did_something)
Common::SleepCurrentThread(1); Common::SleepCurrentThread(1);
#endif
} }
} }