Zebediah Figura : wineusb.sys: Move the event handling loop to the Unix library.

Alexandre Julliard julliard at winehq.org
Tue Jul 12 16:44:21 CDT 2022


Module: wine
Branch: master
Commit: 92ae93d752a80c1d9dd28bbeac733ef5e4b49bfc
URL:    https://gitlab.winehq.org/wine/wine/-/commit/92ae93d752a80c1d9dd28bbeac733ef5e4b49bfc

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Tue Jul  5 23:20:26 2022 -0500

wineusb.sys: Move the event handling loop to the Unix library.

---

 dlls/wineusb.sys/unixlib.c | 29 +++++++++++++++++++++++++++++
 dlls/wineusb.sys/unixlib.h |  2 ++
 dlls/wineusb.sys/wineusb.c | 14 ++------------
 3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/dlls/wineusb.sys/unixlib.c b/dlls/wineusb.sys/unixlib.c
index cdc84d98ede..ee8679e33a2 100644
--- a/dlls/wineusb.sys/unixlib.c
+++ b/dlls/wineusb.sys/unixlib.c
@@ -22,6 +22,7 @@
 #pragma makedep unix
 #endif
 
+#include <stdbool.h>
 #include <libusb.h>
 #include "ntstatus.h"
 #define WIN32_NO_STATUS
@@ -32,6 +33,32 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(wineusb);
 
+static bool thread_shutdown;
+
+static NTSTATUS usb_main_loop(void *args)
+{
+    int ret;
+
+    TRACE("Starting libusb event thread.\n");
+
+    while (!thread_shutdown)
+    {
+        if ((ret = libusb_handle_events(NULL)))
+            ERR("Error handling events: %s\n", libusb_strerror(ret));
+    }
+
+    TRACE("Shutting down libusb event thread.\n");
+    return STATUS_SUCCESS;
+}
+
+static NTSTATUS usb_exit(void *args)
+{
+    thread_shutdown = true;
+    libusb_interrupt_event_handler(NULL);
+
+    return STATUS_SUCCESS;
+}
+
 static NTSTATUS usb_cancel_transfer(void *args)
 {
     const struct usb_cancel_transfer_params *params = args;
@@ -46,5 +73,7 @@ static NTSTATUS usb_cancel_transfer(void *args)
 const unixlib_entry_t __wine_unix_call_funcs[] =
 {
 #define X(name) [unix_ ## name] = name
+    X(usb_main_loop),
+    X(usb_exit),
     X(usb_cancel_transfer),
 };
diff --git a/dlls/wineusb.sys/unixlib.h b/dlls/wineusb.sys/unixlib.h
index d046062cd5f..6c037b20eef 100644
--- a/dlls/wineusb.sys/unixlib.h
+++ b/dlls/wineusb.sys/unixlib.h
@@ -32,6 +32,8 @@ struct usb_cancel_transfer_params
 
 enum unix_funcs
 {
+    unix_usb_main_loop,
+    unix_usb_exit,
     unix_usb_cancel_transfer,
 };
 
diff --git a/dlls/wineusb.sys/wineusb.c b/dlls/wineusb.sys/wineusb.c
index 9e8d78ccf05..66fe3778d64 100644
--- a/dlls/wineusb.sys/wineusb.c
+++ b/dlls/wineusb.sys/wineusb.c
@@ -376,7 +376,6 @@ static void remove_usb_device(libusb_device *libusb_device)
     }
 }
 
-static BOOL thread_shutdown;
 static HANDLE libusb_event_thread, event_thread;
 
 static int LIBUSB_CALL hotplug_cb(libusb_context *context, libusb_device *device,
@@ -393,19 +392,11 @@ static int LIBUSB_CALL hotplug_cb(libusb_context *context, libusb_device *device
 static DWORD CALLBACK libusb_event_thread_proc(void *arg)
 {
     static const struct usb_event shutdown_event = {.type = USB_EVENT_SHUTDOWN};
-    int ret;
-
-    TRACE("Starting libusb event thread.\n");
 
-    while (!thread_shutdown)
-    {
-        if ((ret = libusb_handle_events(NULL)))
-            ERR("Error handling events: %s\n", libusb_strerror(ret));
-    }
+    __wine_unix_call(unix_handle, unix_usb_main_loop, NULL);
 
     queue_event(&shutdown_event);
 
-    TRACE("Shutting down libusb event thread.\n");
     return 0;
 }
 
@@ -517,8 +508,7 @@ static NTSTATUS fdo_pnp(IRP *irp)
             struct usb_device *device, *cursor;
 
             libusb_hotplug_deregister_callback(NULL, hotplug_cb_handle);
-            thread_shutdown = TRUE;
-            libusb_interrupt_event_handler(NULL);
+            __wine_unix_call(unix_handle, unix_usb_exit, NULL);
             WaitForSingleObject(libusb_event_thread, INFINITE);
             CloseHandle(libusb_event_thread);
             WaitForSingleObject(event_thread, INFINITE);




More information about the wine-cvs mailing list