diff options
Diffstat (limited to 'libusb/os/poll_windows.c')
-rw-r--r-- | libusb/os/poll_windows.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index aa7082d..2075468 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -260,7 +260,9 @@ void exit_polling(void) for (i=0; i<MAX_FDS; i++) { // Cancel any async I/O (handle can be invalid) - cancel_io(i); + if (!HasOverlappedIoCompleted(poll_fd[i].overlapped)) { + cancel_io(i); + } // If anything was pending on that I/O, it should be // terminating, and we should be able to access the fd // mutex lock before too long @@ -291,7 +293,9 @@ void exit_polling(void) __inline void _init_read_marker(int index) { // Cancel any read operation in progress - cancel_io(index); + if (!HasOverlappedIoCompleted(poll_fd[index].overlapped)) { + cancel_io(index); + } // Setup a new async read on our marker reset_overlapped(poll_fd[index].overlapped); if (!ReadFile(poll_fd[index].handle, &_poll_fd[index].marker, 1, NULL, poll_fd[index].overlapped)) { @@ -493,7 +497,14 @@ struct winfd usbi_create_fd(HANDLE handle, int access_mode) void _free_index(int index) { // Cancel any async IO (Don't care about the validity of our handles for this) - cancel_io(index); + // This could cause a problem with the libusb0.sys back end and there is + // no CancelIoEx(), because we may be in a different thread to the + // one that is using this fd, and we could kill another threads + // io by mistake! + // + if (!HasOverlappedIoCompleted(poll_fd[index].overlapped)) { + cancel_io(index); + } // close fake handle for devices if ( (poll_fd[index].handle != INVALID_HANDLE_VALUE) && (poll_fd[index].handle != 0) && (GetFileType(poll_fd[index].handle) == FILE_TYPE_UNKNOWN) ) { |