io: Fix race condition in handle_timeout()
authorJoost Muller <joostmuller@gmail.com>
Wed, 20 Jul 2016 08:58:57 +0000 (10:58 +0200)
committerNathan Hjelm <hjelmn@me.com>
Fri, 22 Jul 2016 04:59:35 +0000 (22:59 -0600)
commitbd8d5b5019b72b2dc2d074d96c9992e2f6e7e0b7
tree0a6b6d04620e03e683d858c79cb824873049b07a
parent9afb5c0caf7778d8757ddabadca16aebd7819810
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>
libusb/io.c
libusb/version_nano.h