Hello,
I have recently begun looking thoroughly into the Dolphin implementation, and while looking into how it handles GCC Adapter polling, I was very surprised to find the following code (Source/Core/InputCommon/GCAdapter.cpp) :
This is an odd way of implementing polling, with the first implementation one would think of being periodic polling (especially since, I believe, the USB standard expects interrupt transfers to be periodic - not that it matters in the adapter's case).
Yet, as I interpret it, here we yield the CPU after each USB transfer request, and do another one when the CPU is kind enough to let this thread resume execution. (Looking at USB request block trace, with little CPU load, on my computer, this actually behaved close to periodic behavior - ~every 0.8ms)
I was unable to find an explanation of why this is done the way it is. Since this is quite critical code, I suppose there is a good and technically advanced reason for it, and was hoping whoever knows could explain me.
Thanks !
I have recently begun looking thoroughly into the Dolphin implementation, and while looking into how it handles GCC Adapter polling, I was very surprised to find the following code (Source/Core/InputCommon/GCAdapter.cpp) :
Code:
static void Read()
{
int payload_size = 0;
while (s_adapter_thread_running.IsSet())
{
libusb_interrupt_transfer(s_handle, s_endpoint_in, s_controller_payload_swap,
sizeof(s_controller_payload_swap), &payload_size, 16);
{
std::lock_guard<std::mutex> lk(s_mutex);
std::swap(s_controller_payload_swap, s_controller_payload);
s_controller_payload_size.store(payload_size);
}
Common::YieldCPU();
}
}
This is an odd way of implementing polling, with the first implementation one would think of being periodic polling (especially since, I believe, the USB standard expects interrupt transfers to be periodic - not that it matters in the adapter's case).
Yet, as I interpret it, here we yield the CPU after each USB transfer request, and do another one when the CPU is kind enough to let this thread resume execution. (Looking at USB request block trace, with little CPU load, on my computer, this actually behaved close to periodic behavior - ~every 0.8ms)
I was unable to find an explanation of why this is done the way it is. Since this is quite critical code, I suppose there is a good and technically advanced reason for it, and was hoping whoever knows could explain me.
Thanks !