Fix #56 race condition causing delayed completion of sync transfers
The sync API had a race where it would check a condition to know if it
needed to call a libusb_handle_events() function. However, the check
was done outside of the lock that is held while the condition is set,
so another thread could completely serve whatever was needed to make
the condition true between it being checked and the event handler being
called. This situation would be detected after a libusb-internal timeout
of 60 seconds, after which the transfer would be completed without
error, but with significant delay.
Original patch at http://marc.info/?l=libusb-devel&m=
127252114815709
Changes by Hans de Goede:
- Renamed the "race-proof" functions from libusb_handle_events*_check()
to libusb_handle_events*_completed()
- Drop r = 0 setting in libusb_handle_events_timeout_completed()
(to make both completed checking cases identical flow wise)
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
[stuge: Simplify libusb_handle_events_timeout() change with a goto]
[pbatard: Fix _handle_events_timeout() and _completed() definitions]