Hi Folks, I've got a few issues with a MIDI driver that I'm developing, and so far, my research has turned up nothing. The MIDI driver is based on the SampleUSBMIDI driver project, and although it is working, but it has some strange behaviors that may be causing other problems with the device. The first issue we are having is in the USBDevice class during the OpenAndConfigure() method. For some reason, the call to USBDeviceOpen() always returns kIOReturnExclusiveAccess from the device. As such, I've had to change this class to allow it to continue, as it normally should return upon receiving anything other than kIOReturnSuccess. Is there any particular reason that this call would return kIOReturnExclusiveAccess, even when it is not being used by any other application, and also after "fresh" reboots? Is it possible that there could be an issue with our firmware or hardware which would be causing this? The device also has a corresponding audio driver... is there any chance that this could cause this error?
While the device runs normally (despite the above return errors), I suspect that some of these "soft" errors could be causing more serious problems for some of our users. Also, I believe that this behavior is responsible for a related call to USBDeviceClose() failing during the driver destructor with a code of kIOReturnNotOpen. I think that this occurs due to SetConfiguration() not being called in USBDevice::OpenAndConfigure(), since the error code from USBDeviceOpen() is not IOReturnSuccess. Calling SetConfiguration() with anything other than kIOReturnSuccess crashes the driver, so I have left the error checking mechanisms in, and the call is never getting executed. Is there something in the SetConfiguration() method that "marks" the device as being open for the system so it could be cleanly closed later on?
Finally, the last question I have is in regards to semaphores being used in MIDI drivers. Presently, our driver has three mutexes that are used to protect read/write overlaps. While I think that these mutexes are correctly implemented and stable, I am still a bit uneasy about their presence in the driver. Generally speaking, is it safe to use semaphores in MIDI drivers?
I have read that some hosts, such as Pro Tools, have many problems dealing with plugins using semaphores. Could a plugin accessing such a MIDI driver with semaphores also cause such problems?
Also, is there a preferred threading library that we should be using? At present, we are just using pthreads, but I've read that IOKit provides some of this functionality itself.