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:
Martin Ling
2022-07-04 18:00:07 +01:00
parent 743b2c76e2
commit 0724bd36eb

View File

@ -1695,14 +1695,14 @@ static void transfer_finished(struct hackrf_device* device, struct libusb_transf
device->streaming = false;
// If this is the last transfer, signal that all are now finished.
if (device->active_transfers == 1) {
pthread_mutex_lock(&device->all_finished_lock);
if (device->active_transfers == 1) {
device->active_transfers = 0;
pthread_cond_signal(&device->all_finished_cv);
pthread_mutex_unlock(&device->all_finished_lock);
} else {
device->active_transfers--;
}
pthread_mutex_unlock(&device->all_finished_lock);
}
static void LIBUSB_CALL hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer)