From c07d0c2d2f6f7b0eb6e92cc6204bf05037957e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 1 Sep 2014 15:43:52 +0200 Subject: Imported Upstream version 1.6.3 --- spectro/usbio_nt.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'spectro/usbio_nt.c') diff --git a/spectro/usbio_nt.c b/spectro/usbio_nt.c index 1711f0d..de9b265 100644 --- a/spectro/usbio_nt.c +++ b/spectro/usbio_nt.c @@ -25,7 +25,7 @@ #include #include -#define DEBUG /* Turn on debug messages */ +#undef DEBUG /* Turn on debug messages */ #define LIBUSBW1_MAX_DEVICES 255 #define LIBUSBW1_PATH_MAX 512 @@ -117,7 +117,8 @@ icompaths *p unsigned char buf[IUSB_DESC_TYPE_DEVICE_SIZE]; _snprintf(dpath, LIBUSBW1_PATH_MAX - 1,"\\\\.\\libusb0-%04d", i+1); - a1logd(p->log, 6, "usb_get_paths opening device '%s'\n",dpath); + if (i < 16) /* Suppress messages on unlikely ports */ + a1logd(p->log, 6, "usb_get_paths opening device '%s'\n",dpath); if ((handle = CreateFile(dpath, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE) { @@ -323,6 +324,8 @@ icompaths *p /* Add the path and ep info to the list */ if ((rv = p->add_usb(p, pname, vid, pid, nep10, usbd, itype)) != ICOM_OK) return rv; + + } else { free(usbd); } @@ -409,10 +412,6 @@ void usb_close_port(icoms *p) { } CloseHandle(p->usbd->handle); - free(p->usbd->dpath); - free(p->usbd); - p->usbd = NULL; - a1logd(p->log, 6, "usb_close_port: usb port has been released and closed\n"); } p->is_open = 0; @@ -565,6 +564,7 @@ char **pnames /* List of process names to try and kill before opening */ /* -------------------------------------------------------------- */ /* Our universal USB transfer function */ +/* It appears that we may return a timeout with valid characters. */ static int icoms_usb_transaction( icoms *p, usb_cancelt *cancelt, @@ -596,12 +596,6 @@ static int icoms_usb_transaction( if ((olaps.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) == NULL) return ICOM_SYS; - if (cancelt != NULL) { - usb_lock_cancel(cancelt); - cancelt->hcancel = (void *)&endpoint; - usb_unlock_cancel(cancelt); - } - memset(&req, 0, sizeof(libusb_request)); req.endpoint.endpoint = endpoint; @@ -616,9 +610,17 @@ static int icoms_usb_transaction( goto done; } + if (cancelt != NULL) { + amutex_lock(cancelt->cmtx); + cancelt->hcancel = (void *)&endpoint; + cancelt->state = 1; + amutex_unlock(cancelt->cond); /* Signal any thread waiting for IO start */ + amutex_unlock(cancelt->cmtx); + } + if (WaitForSingleObject(olaps.hEvent, timeout) == WAIT_TIMEOUT) { - /* Cancel the operation */ + /* Cancel the operation, because it timed out */ memset(&req, 0, sizeof(libusb_request)); req.endpoint.endpoint = endpoint; req.timeout = LIBUSBW1_DEFAULT_TIMEOUT; @@ -638,9 +640,12 @@ static int icoms_usb_transaction( } done:; if (cancelt != NULL) { - usb_lock_cancel(cancelt); + amutex_lock(cancelt->cmtx); cancelt->hcancel = (void *)NULL; - usb_unlock_cancel(cancelt); + if (cancelt->state == 0) + amutex_unlock(cancelt->cond); /* Make sure this gets unlocked */ + cancelt->state = 2; + amutex_unlock(cancelt->cmtx); } CloseHandle(olaps.hEvent); @@ -815,7 +820,7 @@ int icoms_usb_cancel_io( usb_cancelt *cancelt ) { int rv = ICOM_OK; - usb_lock_cancel(cancelt); + amutex_lock(cancelt->cmtx); if (cancelt->hcancel != NULL) { libusb_request req; @@ -828,7 +833,7 @@ int icoms_usb_cancel_io( a1logd(p->log, 1, "icoms_usb_cancel_io: failed with 0x%x\n",rv); } } - usb_unlock_cancel(cancelt); + amutex_unlock(cancelt->cmtx); return rv; } -- cgit v1.2.3