Extend scope of transfer_lock in callback.

This commit is contained in:
Martin Ling
2022-09-26 13:29:53 +01:00
parent caf0cfde87
commit 559a45bd6b

View File

@ -1834,15 +1834,10 @@ hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer)
device->streaming = false; device->streaming = false;
device->flush = false; device->flush = false;
} }
// Now we can release the lock. Our transfer was either
// cancelled or restarted, not both.
pthread_mutex_unlock(&device->transfer_lock);
// If a data transfer was resubmitted successfully, we're done. // If a data transfer was resubmitted successfully, we're done.
if (resubmit && result == LIBUSB_SUCCESS) if (!resubmit || result != LIBUSB_SUCCESS) {
return; // No further calls should be made to the TX callback.
// Otherwise, no further calls should be made to the TX callback.
device->streaming = false; device->streaming = false;
// If this is the last transfer, signal that all are now finished. // If this is the last transfer, signal that all are now finished.
@ -1856,6 +1851,11 @@ hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer)
device->active_transfers--; device->active_transfers--;
} }
pthread_mutex_unlock(&device->all_finished_lock); pthread_mutex_unlock(&device->all_finished_lock);
}
// Now we can release the lock. Our transfer was either
// cancelled or restarted, not both.
pthread_mutex_unlock(&device->transfer_lock);
} }
static int kill_transfer_thread(hackrf_device* device) static int kill_transfer_thread(hackrf_device* device)