Lock the whole code block that touches active transfer count.
I believe this was safe before, because this code is only called from the transfer thread, and the condition being protected is just whether the count is zero, not the actual value of the count. However, this isn't performance critical and it's a lot easier to reason about the code if we just hold the lock for this whole section.
This commit is contained in:
@ -1695,14 +1695,14 @@ static void transfer_finished(struct hackrf_device* device, struct libusb_transf
|
|||||||
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.
|
||||||
|
pthread_mutex_lock(&device->all_finished_lock);
|
||||||
if (device->active_transfers == 1) {
|
if (device->active_transfers == 1) {
|
||||||
pthread_mutex_lock(&device->all_finished_lock);
|
|
||||||
device->active_transfers = 0;
|
device->active_transfers = 0;
|
||||||
pthread_cond_signal(&device->all_finished_cv);
|
pthread_cond_signal(&device->all_finished_cv);
|
||||||
pthread_mutex_unlock(&device->all_finished_lock);
|
|
||||||
} else {
|
} else {
|
||||||
device->active_transfers--;
|
device->active_transfers--;
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&device->all_finished_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LIBUSB_CALL hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer)
|
static void LIBUSB_CALL hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer)
|
||||||
|
Reference in New Issue
Block a user