From 4810d1f9922a88778f1afaf5b8136125034b3f0d Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 22 Sep 2022 12:46:42 +0100 Subject: [PATCH] Fold transfer_finished function into libusb transfer callback. --- host/libhackrf/src/hackrf.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index acbd4d1c..9dbb338c 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -1768,26 +1768,6 @@ static void* transfer_threadproc(void* arg) return NULL; } -static void transfer_finished( - struct hackrf_device* device, - struct libusb_transfer* finished_transfer) -{ - // If a transfer finished for any reason, we're shutting down. - device->streaming = false; - - // If this is the last transfer, signal that all are now finished. - pthread_mutex_lock(&device->all_finished_lock); - if (device->active_transfers == 1) { - if (!device->flush) { - device->active_transfers = 0; - pthread_cond_broadcast(&device->all_finished_cv); - } - } else { - device->active_transfers--; - } - pthread_mutex_unlock(&device->all_finished_lock); -} - static void LIBUSB_CALL hackrf_libusb_flush_callback(struct libusb_transfer* usb_transfer) { // TX buffer is now flushed, so proceed with signalling completion. @@ -1857,8 +1837,20 @@ hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer) if (resubmit && result == LIBUSB_SUCCESS) return; - // Otherwise, a transfer has now finished. - transfer_finished(device, usb_transfer); + // Otherwise, no further calls should be made to the TX callback. + device->streaming = false; + + // If this is the last transfer, signal that all are now finished. + pthread_mutex_lock(&device->all_finished_lock); + if (device->active_transfers == 1) { + if (!device->flush) { + device->active_transfers = 0; + pthread_cond_broadcast(&device->all_finished_cv); + } + } else { + device->active_transfers--; + } + pthread_mutex_unlock(&device->all_finished_lock); } static int kill_transfer_thread(hackrf_device* device)