- if (!ctx->usb_source_present)
- return SR_OK;
-
-#ifdef _WIN32
- /* Signal the USB wait thread to stop, then unblock it so it does. */
- ctx->usb_thread_running = FALSE;
- SetEvent(ctx->usb_wait_request_event);
- libusb_unlock_events(ctx->libusb_ctx);
- /* Wait for USB wait thread to terminate. */
- g_thread_join(ctx->usb_thread);
- /* Remove USB event from session poll set. */
- sr_session_source_remove_pollfd(session, &ctx->usb_pollfd);
- /* Close event handles that were used between threads. */
- CloseHandle(ctx->usb_wait_request_event);
- CloseHandle(ctx->usb_wait_complete_event);
-#else
- const struct libusb_pollfd **lupfd;
- unsigned int i;
-
- lupfd = libusb_get_pollfds(ctx->libusb_ctx);
- for (i = 0; lupfd[i]; i++)
- sr_session_source_remove(session, lupfd[i]->fd);
- free(lupfd);
-#endif
- ctx->usb_source_present = FALSE;
-
- return SR_OK;
+ return sr_session_source_remove_internal(session,
+ (gintptr)ctx->libusb_ctx);