Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 559a45b

Browse files
committed
Extend scope of transfer_lock in callback.
1 parent caf0cfd commit 559a45b

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

host/libhackrf/src/hackrf.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,28 +1834,28 @@ hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer)
18341834
device->streaming = false;
18351835
device->flush = false;
18361836
}
1837-
// Now we can release the lock. Our transfer was either
1838-
// cancelled or restarted, not both.
1839-
pthread_mutex_unlock(&device->transfer_lock);
18401837

18411838
// If a data transfer was resubmitted successfully, we're done.
1842-
if (resubmit && result == LIBUSB_SUCCESS)
1843-
return;
1844-
1845-
// Otherwise, no further calls should be made to the TX callback.
1846-
device->streaming = false;
1839+
if (!resubmit || result != LIBUSB_SUCCESS) {
1840+
// No further calls should be made to the TX callback.
1841+
device->streaming = false;
18471842

1848-
// If this is the last transfer, signal that all are now finished.
1849-
pthread_mutex_lock(&device->all_finished_lock);
1850-
if (device->active_transfers == 1) {
1851-
if (!device->flush) {
1852-
device->active_transfers = 0;
1853-
pthread_cond_broadcast(&device->all_finished_cv);
1843+
// If this is the last transfer, signal that all are now finished.
1844+
pthread_mutex_lock(&device->all_finished_lock);
1845+
if (device->active_transfers == 1) {
1846+
if (!device->flush) {
1847+
device->active_transfers = 0;
1848+
pthread_cond_broadcast(&device->all_finished_cv);
1849+
}
1850+
} else {
1851+
device->active_transfers--;
18541852
}
1855-
} else {
1856-
device->active_transfers--;
1853+
pthread_mutex_unlock(&device->all_finished_lock);
18571854
}
1858-
pthread_mutex_unlock(&device->all_finished_lock);
1855+
1856+
// Now we can release the lock. Our transfer was either
1857+
// cancelled or restarted, not both.
1858+
pthread_mutex_unlock(&device->transfer_lock);
18591859
}
18601860

18611861
static int kill_transfer_thread(hackrf_device* device)

0 commit comments

Comments
 (0)