Skip to content

Commit

Permalink
libbladeRF: [WIP] Removed unnecessary mutex acquisition in CyAPI probe()
Browse files Browse the repository at this point in the history
Using open_device() is overkill, as we just want to open a device handle to
read member variables for VID, PID, and serial #; we're not writing to the
device.

*NOTE:* The CyAPI docs say that this will Close() the device first if
        needed. This may be a bogus "fix" for #364, if the already opened device
        handle is beings used when the probe() is called.
  • Loading branch information
jynik committed Jan 23, 2015
1 parent 955930a commit da459f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions host/libraries/libbladeRF/src/backend/usb/cyapi.c
Expand Up @@ -87,6 +87,7 @@ static inline struct stream_data * get_stream_data(struct bladerf_stream *s)
return (struct stream_data *) s->backend_data;
}


static int open_device(CCyUSBDevice *dev, int instance, HANDLE *mutex)
{
int status = 0;
Expand Down Expand Up @@ -154,18 +155,18 @@ static bool device_matches_target(CCyUSBDevice *dev,
static int cyapi_probe(backend_probe_target probe_target,
struct bladerf_devinfo_list *info_list)
{
int status = 0;
CCyUSBDevice *dev = new CCyUSBDevice(NULL, driver_guid);
if (dev == NULL) {
return BLADERF_ERR_MEM;
}

for (int i = 0; i < dev->DeviceCount() && status == 0; i++) {
for (int i = 0; i < dev->DeviceCount(); i++) {
struct bladerf_devinfo info;
HANDLE mutex;
bool opened;
int status;

status = open_device(dev, i, &mutex);
if (status == 0) {
opened = dev->Open(i);
if (opened) {
if (device_matches_target(dev, probe_target)) {
const size_t max_serial = sizeof(info.serial) - 1;
info.instance = i;
Expand All @@ -175,7 +176,7 @@ static int cyapi_probe(backend_probe_target probe_target,
info.usb_bus = 0; /* CyAPI doesn't provide this */
info.backend = BLADERF_BACKEND_CYPRESS;
status = bladerf_devinfo_list_add(info_list, &info);
if (status) {
if (status != 0) {
log_error("Could not add device to list: %s\n",
bladerf_strerror(status));
} else {
Expand All @@ -185,12 +186,11 @@ static int cyapi_probe(backend_probe_target probe_target,
}

dev->Close();
CloseHandle(mutex);
}
}

delete dev;
return status;
return 0;

}

Expand Down

0 comments on commit da459f2

Please sign in to comment.