Merge pull request #558 from dominicgs/multiple_hackrf_stop_rx_issue_463

Fix multiple hackrf stop rx
This commit is contained in:
Michael Ossmann
2018-12-06 15:48:53 -07:00
committed by GitHub

View File

@ -114,6 +114,7 @@ struct hackrf_device {
volatile bool streaming; /* volatile shared between threads (read only) */ volatile bool streaming; /* volatile shared between threads (read only) */
void* rx_ctx; void* rx_ctx;
void* tx_ctx; void* tx_ctx;
volatile bool do_exit;
unsigned char buffer[TRANSFER_COUNT * TRANSFER_BUFFER_SIZE]; unsigned char buffer[TRANSFER_COUNT * TRANSFER_BUFFER_SIZE];
}; };
@ -147,8 +148,6 @@ hackrf_usb_api_version_read(device, &usb_version); \
if(usb_version < version) \ if(usb_version < version) \
return HACKRF_ERROR_USB_API_VERSION; return HACKRF_ERROR_USB_API_VERSION;
static volatile bool do_exit = false;
static const uint16_t hackrf_usb_vid = 0x1d50; static const uint16_t hackrf_usb_vid = 0x1d50;
static const uint16_t hackrf_jawbreaker_usb_pid = 0x604b; static const uint16_t hackrf_jawbreaker_usb_pid = 0x604b;
static const uint16_t hackrf_one_usb_pid = 0x6089; static const uint16_t hackrf_one_usb_pid = 0x6089;
@ -158,9 +157,9 @@ static uint16_t open_devices = 0;
static libusb_context* g_libusb_context = NULL; static libusb_context* g_libusb_context = NULL;
int last_libusb_error = LIBUSB_SUCCESS; int last_libusb_error = LIBUSB_SUCCESS;
static void request_exit(void) static void request_exit(hackrf_device* device)
{ {
do_exit = true; device->do_exit = true;
} }
static int cancel_transfers(hackrf_device* device) static int cancel_transfers(hackrf_device* device)
@ -569,7 +568,7 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d
lib_device->callback = NULL; lib_device->callback = NULL;
lib_device->transfer_thread_started = false; lib_device->transfer_thread_started = false;
lib_device->streaming = false; lib_device->streaming = false;
do_exit = false; lib_device->do_exit = false;
result = allocate_transfers(lib_device); result = allocate_transfers(lib_device);
if( result != 0 ) if( result != 0 )
@ -1479,7 +1478,7 @@ static void* transfer_threadproc(void* arg)
int error; int error;
struct timeval timeout = { 0, 500000 }; struct timeval timeout = { 0, 500000 };
while( (device->streaming) && (do_exit == false) ) while( (device->streaming) && (device->do_exit == false) )
{ {
error = libusb_handle_events_timeout(g_libusb_context, &timeout); error = libusb_handle_events_timeout(g_libusb_context, &timeout);
if( (error != 0) && (error != LIBUSB_ERROR_INTERRUPTED) ) if( (error != 0) && (error != LIBUSB_ERROR_INTERRUPTED) )
@ -1510,12 +1509,12 @@ static void LIBUSB_CALL hackrf_libusb_transfer_callback(struct libusb_transfer*
{ {
if( libusb_submit_transfer(usb_transfer) < 0) if( libusb_submit_transfer(usb_transfer) < 0)
{ {
request_exit(); request_exit(device);
}else { }else {
return; return;
} }
}else { }else {
request_exit(); request_exit(device);
} }
} else { } else {
/* Other cases LIBUSB_TRANSFER_NO_DEVICE /* Other cases LIBUSB_TRANSFER_NO_DEVICE
@ -1523,7 +1522,7 @@ static void LIBUSB_CALL hackrf_libusb_transfer_callback(struct libusb_transfer*
LIBUSB_TRANSFER_STALL, LIBUSB_TRANSFER_OVERFLOW LIBUSB_TRANSFER_STALL, LIBUSB_TRANSFER_OVERFLOW
LIBUSB_TRANSFER_CANCELLED ... LIBUSB_TRANSFER_CANCELLED ...
*/ */
request_exit(); /* Fatal error stop transfer */ request_exit(device); /* Fatal error stop transfer */
} }
} }
@ -1532,7 +1531,7 @@ static int kill_transfer_thread(hackrf_device* device)
void* value; void* value;
int result; int result;
request_exit(); request_exit(device);
if( device->transfer_thread_started != false ) if( device->transfer_thread_started != false )
{ {
@ -1560,7 +1559,7 @@ static int create_transfer_thread(hackrf_device* device,
if( device->transfer_thread_started == false ) if( device->transfer_thread_started == false )
{ {
device->streaming = false; device->streaming = false;
do_exit = false; device->do_exit = false;
result = prepare_transfers( result = prepare_transfers(
device, endpoint_address, device, endpoint_address,
@ -1594,7 +1593,7 @@ int ADDCALL hackrf_is_streaming(hackrf_device* device)
if( (device->transfer_thread_started == true) && if( (device->transfer_thread_started == true) &&
(device->streaming == true) && (device->streaming == true) &&
(do_exit == false) ) (device->do_exit == false) )
{ {
return HACKRF_TRUE; return HACKRF_TRUE;
} else { } else {