Commit 92ae93d7 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

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

parent b3a47cf1
......@@ -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),
};
......@@ -32,6 +32,8 @@ struct usb_cancel_transfer_params
enum unix_funcs
{
unix_usb_main_loop,
unix_usb_exit,
unix_usb_cancel_transfer,
};
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment