From 4cccbed825fe1dc138121640a6497d7d05aac159 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Tue, 10 Apr 2012 13:30:24 +0100 Subject: Windows: Remove #define options and use same set of defaults * The DYNAMIC_FDS, AUTO_CLAIM and FORCE_INSTANT_TIMEOUTS options were introduced for development/testing and don't appear to be used by the Windows backend users => remove them. --- libusb/os/poll_windows.c | 94 ------------------------------------------------ libusb/os/poll_windows.h | 5 --- libusb/os/windows_usb.c | 43 ---------------------- libusb/os/windows_usb.h | 2 -- 4 files changed, 144 deletions(-) diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index 2201ffa..6bb8cd6 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -90,12 +90,6 @@ struct { // globals BOOLEAN is_polling_set = FALSE; -#if defined(DYNAMIC_FDS) -HANDLE fd_update = INVALID_HANDLE_VALUE; // event to notify poll of fd update -HANDLE new_fd[MAX_FDS]; // overlapped event handles for fds created since last poll -unsigned nb_new_fds = 0; // nb new fds created since last poll -usbi_mutex_t new_fd_mutex; // mutex required for the above -#endif LONG pipe_number = 0; static volatile LONG compat_spinlock = 0; @@ -143,16 +137,6 @@ void init_polling(void) _poll_fd[i].thread_id = 0; InitializeCriticalSection(&_poll_fd[i].mutex); } -#if defined(DYNAMIC_FDS) - // We need to create an update event so that poll is warned when there - // are new/deleted fds during a timeout wait operation - fd_update = CreateEvent(NULL, TRUE, FALSE, NULL); - if (fd_update == NULL) { - usbi_err(NULL, "unable to create update event"); - } - usbi_mutex_init(&new_fd_mutex, NULL); - nb_new_fds = 0; -#endif is_polling_set = TRUE; } compat_spinlock = 0; @@ -249,11 +233,6 @@ void exit_polling(void) } } poll_fd[i] = INVALID_WINFD; -#if defined(DYNAMIC_FDS) - usbi_mutex_destroy(&new_fd_mutex); - CloseHandle(fd_update); - fd_update = INVALID_HANDLE_VALUE; -#endif LeaveCriticalSection(&_poll_fd[i].mutex); DeleteCriticalSection(&_poll_fd[i].mutex); } @@ -404,13 +383,6 @@ struct winfd usbi_create_fd(HANDLE handle, int access_mode) wfd.overlapped = overlapped; memcpy(&poll_fd[i], &wfd, sizeof(struct winfd)); LeaveCriticalSection(&_poll_fd[i].mutex); -#if defined(DYNAMIC_FDS) - usbi_mutex_lock(&new_fd_mutex); - new_fd[nb_new_fds++] = overlapped->hEvent; - usbi_mutex_unlock(&new_fd_mutex); - // Notify poll that fds have been updated - SetEvent(fd_update); -#endif return wfd; } } @@ -554,21 +526,6 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) DWORD nb_handles_to_wait_on = 0; DWORD ret; -#if defined(DYNAMIC_FDS) - DWORD nb_extra_handles = 0; - unsigned j; - - // To address the possibility of missing new fds between the time the new - // pollable fd set is assembled, and the ResetEvent() call below, an - // additional new_fd[] HANDLE table is used for any new fd that was created - // since the last call to poll (see below) - ResetEvent(fd_update); - - // At this stage, any new fd creation will be detected through the fd_update - // event notification, and any previous creation that we may have missed - // will be picked up through the existing new_fd[] table. -#endif - CHECK_INIT_POLLING; triggered = 0; @@ -636,47 +593,13 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) } else { handles_to_wait_on[nb_handles_to_wait_on] = poll_fd[_index].overlapped->hEvent; handle_to_index[nb_handles_to_wait_on] = i; -#if defined(DYNAMIC_FDS) - // If this fd from the poll set is also part of the new_fd event handle table, remove it - usbi_mutex_lock(&new_fd_mutex); - for (j=0; j= 0) && ((DWORD)object_index < nb_handles_to_wait_on)) { -#if defined(DYNAMIC_FDS) - if ((DWORD)object_index >= (nb_handles_to_wait_on-nb_extra_handles)) { - // Detected fd update => flag a poll interruption - if ((DWORD)object_index == (nb_handles_to_wait_on-1)) - poll_dbg(" dynamic_fds: fd_update event"); - else - poll_dbg(" dynamic_fds: new fd I/O event"); - errno = EINTR; - triggered = -1; - goto poll_exit; - } -#endif poll_dbg(" completed after wait"); i = handle_to_index[object_index]; _index = _fd_to_index_and_lock(fds[i].fd); @@ -722,11 +633,6 @@ poll_exit: if (handle_to_index != NULL) { free(handle_to_index); } -#if defined(DYNAMIC_FDS) - usbi_mutex_lock(&new_fd_mutex); - nb_new_fds = 0; - usbi_mutex_unlock(&new_fd_mutex); -#endif return triggered; } diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h index 1fe3669..570f67d 100644 --- a/libusb/os/poll_windows.h +++ b/libusb/os/poll_windows.h @@ -26,11 +26,6 @@ #pragma warning(disable:4127) // conditional expression is constant #endif -// Uncomment to have poll return with EINTR as soon as a new transfer (fd) is added -// This should result in a LIBUSB_ERROR_INTERRUPTED being returned by libusb calls, -// which should give the app an opportunity to resubmit a new fd set. -//#define DYNAMIC_FDS - // Handle synchronous completion through the overlapped structure #if !defined(STATUS_REPARSE) // reuse the REPARSE status code #define STATUS_REPARSE ((LONG)0x00000104L) diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 655edf3..709157a 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -21,14 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -// COMPILATION OPTIONS: -// - Should libusbx automatically claim (and release) the interfaces it requires? -#define AUTO_CLAIM -// - Forces instant overlapped completion on timeouts: can prevents extensive -// wait in poll, after a timeout, but might affect subsequent API calls. -// ***USE AT YOUR OWN RISKS*** -//#define FORCE_INSTANT_TIMEOUTS - #include #include #include @@ -100,9 +92,7 @@ const uint64_t epoch_time = UINT64_C(116444736000000000); // 1970.01.01 00:00:00 enum windows_version windows_version = WINDOWS_UNSUPPORTED; // Concurrency static int concurrent_usage = -1; -#if defined(AUTO_CLAIM) usbi_mutex_t autoclaim_lock; -#endif // Timer thread // NB: index 0 is for monotonic and 1 is for the thread exit event HANDLE timer_thread = NULL; @@ -629,7 +619,6 @@ static bool is_api_driver(char* driver, uint8_t api) /* * auto-claiming and auto-release helper functions */ -#if defined(AUTO_CLAIM) static int auto_claim(struct libusb_transfer *transfer, int *interface_number, int api_type) { struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev); @@ -695,8 +684,6 @@ static void auto_release(struct usbi_transfer *itransfer) } usbi_mutex_unlock(&autoclaim_lock); } -#endif - /* * init: libusbx backend init function @@ -749,10 +736,8 @@ static int windows_init(struct libusb_context *ctx) goto init_exit; } -#if defined(AUTO_CLAIM) // We need a lock for proper auto-release usbi_mutex_init(&autoclaim_lock, NULL); -#endif // Initialize pollable file descriptors init_polling(); @@ -1765,10 +1750,8 @@ static void windows_clear_transfer_priv(struct usbi_transfer *itransfer) struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer); usbi_free_fd(transfer_priv->pollable_fd.fd); -#if defined(AUTO_CLAIM) // When auto claim is in use, attempt to release the auto-claimed interface auto_release(itransfer); -#endif } static int submit_bulk_transfer(struct usbi_transfer *itransfer) @@ -1786,9 +1769,6 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) usbi_add_pollfd(ctx, transfer_priv->pollable_fd.fd, (short)(IS_XFERIN(transfer) ? POLLIN : POLLOUT)); -#if !defined(DYNAMIC_FDS) - usbi_fd_notification(ctx); -#endif return LIBUSB_SUCCESS; } @@ -1808,9 +1788,6 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) usbi_add_pollfd(ctx, transfer_priv->pollable_fd.fd, (short)(IS_XFERIN(transfer) ? POLLIN : POLLOUT)); -#if !defined(DYNAMIC_FDS) - usbi_fd_notification(ctx); -#endif return LIBUSB_SUCCESS; } @@ -1829,9 +1806,6 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) } usbi_add_pollfd(ctx, transfer_priv->pollable_fd.fd, POLLIN); -#if !defined(DYNAMIC_FDS) - usbi_fd_notification(ctx); -#endif return LIBUSB_SUCCESS; @@ -1877,14 +1851,7 @@ static int windows_abort_transfers(struct usbi_transfer *itransfer) static int windows_cancel_transfer(struct usbi_transfer *itransfer) { struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer); -#if defined(FORCE_INSTANT_TIMEOUTS) - struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer); - // Forces instant overlapped completion on timeouts - use at your own risks - if (itransfer->flags & USBI_TRANSFER_TIMED_OUT) { - transfer_priv->pollable_fd.overlapped->Internal &= ~STATUS_PENDING; - } -#endif switch (transfer->type) { case LIBUSB_TRANSFER_TYPE_CONTROL: return windows_abort_control(itransfer); @@ -2484,7 +2451,6 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i // It is a requirement for multiple interface devices using WinUSB that you // must first claim the first interface before you claim any other if ((winusb_handle == 0) || (winusb_handle == INVALID_HANDLE_VALUE)) { -#if defined(AUTO_CLAIM) file_handle = handle_priv->interface_handle[0].dev_handle; if (WinUsb_Initialize(file_handle, &winusb_handle)) { handle_priv->interface_handle[0].api_handle = winusb_handle; @@ -2493,10 +2459,6 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i usbi_warn(ctx, "failed to auto-claim interface 0 (required to claim %d with WinUSB)", iface); return LIBUSB_ERROR_ACCESS; } -#else - usbi_warn(ctx, "you must claim interface 0 before you can claim %d with WinUSB", iface); - return LIBUSB_ERROR_ACCESS; -#endif } if (!WinUsb_GetAssociatedInterface(winusb_handle, (UCHAR)(iface-1), &handle_priv->interface_handle[iface].api_handle)) { @@ -2604,14 +2566,9 @@ static int winusb_submit_control_transfer(struct usbi_transfer *itransfer) current_interface = winusb_get_valid_interface(transfer->dev_handle); if (current_interface < 0) { -#if defined(AUTO_CLAIM) if (auto_claim(transfer, ¤t_interface, USB_API_WINUSB) != LIBUSB_SUCCESS) { return LIBUSB_ERROR_NOT_FOUND; } -#else - usbi_warn(ctx, "no interface available for control transfer"); - return LIBUSB_ERROR_NOT_FOUND; -#endif } usbi_dbg("will use interface %d", current_interface); diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h index 0c71110..c07e56a 100644 --- a/libusb/os/windows_usb.h +++ b/libusb/os/windows_usb.h @@ -217,9 +217,7 @@ struct interface_handle_t { struct windows_device_handle_priv { int active_interface; struct interface_handle_t interface_handle[USB_MAXINTERFACES]; -#if defined(AUTO_CLAIM) int autoclaim_count[USB_MAXINTERFACES]; // For auto-release -#endif }; static inline struct windows_device_handle_priv *_device_handle_priv( -- cgit v1.2.1