Skip to content

Instantly share code, notes, and snippets.

@codeman38
Created October 9, 2011 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeman38/1273303 to your computer and use it in GitHub Desktop.
Save codeman38/1273303 to your computer and use it in GitHub Desktop.
Patch to fix deadlock issues in Xbox 360 Controller Driver v.0.10 for Mac OS X
diff -ru 360ControllerSource.0.10/360Controller/_60Controller.cpp 360ControllerSource.0.10a/360Controller/_60Controller.cpp
--- 360ControllerSource.0.10/360Controller/_60Controller.cpp 2011-06-16 13:21:00.000000000 -0400
+++ 360ControllerSource.0.10a/360Controller/_60Controller.cpp 2011-10-09 00:18:14.000000000 -0400
@@ -1,6 +1,7 @@
/*
MICE Xbox 360 Controller driver for Mac OS X
Copyright (C) 2006-2007 Colin Munro
+ Bug fixes contributed by Cody "codeman38" Boisclair
_60Controller.cpp - main source of the driver
@@ -665,69 +666,75 @@
// This handles a completed asynchronous read
void Xbox360Peripheral::ReadComplete(void *parameter,IOReturn status,UInt32 bufferSizeRemaining)
{
- LockRequired locker(mainLock);
- IOReturn err;
- bool reread=!isInactive();
-
- switch(status) {
- case kIOReturnOverrun:
- IOLog("read - kIOReturnOverrun, clearing stall\n");
- if (inPipe != NULL)
- inPipe->ClearStall();
- // Fall through
- case kIOReturnSuccess:
- if (inBuffer != NULL)
- {
- const XBOX360_IN_REPORT *report=(const XBOX360_IN_REPORT*)inBuffer->getBytesNoCopy();
- if((report->header.command==inReport)&&(report->header.size==sizeof(XBOX360_IN_REPORT))) {
- fiddleReport(inBuffer);
- err = padHandler->handleReport(inBuffer, kIOHIDReportTypeInput);
- if(err!=kIOReturnSuccess) {
- IOLog("read - failed to handle report: 0x%.8x\n",err);
- }
- }
- }
- break;
- case kIOReturnNotResponding:
- IOLog("read - kIOReturnNotResponding\n");
- reread=false;
- break;
- default:
- reread=false;
- break;
+ if (padHandler != NULL) // avoid deadlock with release
+ {
+ LockRequired locker(mainLock);
+ IOReturn err;
+ bool reread=!isInactive();
+
+ switch(status) {
+ case kIOReturnOverrun:
+ IOLog("read - kIOReturnOverrun, clearing stall\n");
+ if (inPipe != NULL)
+ inPipe->ClearStall();
+ // Fall through
+ case kIOReturnSuccess:
+ if (inBuffer != NULL)
+ {
+ const XBOX360_IN_REPORT *report=(const XBOX360_IN_REPORT*)inBuffer->getBytesNoCopy();
+ if((report->header.command==inReport)&&(report->header.size==sizeof(XBOX360_IN_REPORT))) {
+ fiddleReport(inBuffer);
+ err = padHandler->handleReport(inBuffer, kIOHIDReportTypeInput);
+ if(err!=kIOReturnSuccess) {
+ IOLog("read - failed to handle report: 0x%.8x\n",err);
+ }
+ }
+ }
+ break;
+ case kIOReturnNotResponding:
+ IOLog("read - kIOReturnNotResponding\n");
+ reread=false;
+ break;
+ default:
+ reread=false;
+ break;
+ }
+ if(reread) QueueRead();
}
- if(reread) QueueRead();
}
void Xbox360Peripheral::SerialReadComplete(void *parameter, IOReturn status, UInt32 bufferSizeRemaining)
{
- LockRequired locker(mainLock);
- bool reread = !isInactive();
-
- switch (status)
+ if (padHandler != NULL) // avoid deadlock with release
{
- case kIOReturnOverrun:
- IOLog("read (serial) - kIOReturnOverrun, clearing stall\n");
- if (serialInPipe != NULL)
- serialInPipe->ClearStall();
- // Fall through
- case kIOReturnSuccess:
- serialHeard = true;
- if (serialInBuffer != NULL)
- SerialMessage(serialInBuffer, serialInBuffer->getCapacity() - bufferSizeRemaining);
- break;
-
- case kIOReturnNotResponding:
- IOLog("read (serial) - kIOReturnNotResponding\n");
- reread = false;
- break;
-
- default:
- reread = false;
- break;
+ LockRequired locker(mainLock);
+ bool reread = !isInactive();
+
+ switch (status)
+ {
+ case kIOReturnOverrun:
+ IOLog("read (serial) - kIOReturnOverrun, clearing stall\n");
+ if (serialInPipe != NULL)
+ serialInPipe->ClearStall();
+ // Fall through
+ case kIOReturnSuccess:
+ serialHeard = true;
+ if (serialInBuffer != NULL)
+ SerialMessage(serialInBuffer, serialInBuffer->getCapacity() - bufferSizeRemaining);
+ break;
+
+ case kIOReturnNotResponding:
+ IOLog("read (serial) - kIOReturnNotResponding\n");
+ reread = false;
+ break;
+
+ default:
+ reread = false;
+ break;
+ }
+ if (reread)
+ QueueSerialRead();
}
- if (reread)
- QueueSerialRead();
}
// Handle a completed asynchronous write
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment