io: Fix race condition in handle_timeout()
There is a race between handle_timeout() the completion functions.
When one thread is in handle_timeout() and another thread wakes
up from a poll(), there exists a window where the transfer has been
cancelled, but its USBI_TRANSFER_TIMED_OUT flag is not set yet.
Therefore, usbi_handle_transfer_completion() is sometimes called
with LIBUSB_TRANSFER_CANCELLED instead of the expected
LIBUSB_TRANSFER_TIMED_OUT.
This change adds transfer and flag locks to the handle_timeout()
function.
Closes #197
Signed-off-by: Nathan Hjelm <hjelmn@me.com>