winebus.sys: Return an event from IOHID bus wait on device removal.

Instead of calling bus_unlink_hid_device or IoInvalidateDeviceRelations.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-08-30 11:22:54 +02:00 committed by Alexandre Julliard
parent 9f09e2a3cb
commit 2457113970
3 changed files with 10 additions and 10 deletions

View File

@ -47,7 +47,6 @@ DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid, WO
DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad,
const platform_vtbl *vtbl, struct unix_device *unix_device) DECLSPEC_HIDDEN; const platform_vtbl *vtbl, struct unix_device *unix_device) DECLSPEC_HIDDEN;
DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) DECLSPEC_HIDDEN; DEVICE_OBJECT *bus_find_hid_device(const WCHAR *bus_id, void *platform_dev) DECLSPEC_HIDDEN;
void bus_unlink_hid_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;
void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN; void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN;
DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function, void *context) DECLSPEC_HIDDEN; DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function, void *context) DECLSPEC_HIDDEN;

View File

@ -97,6 +97,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
static IOHIDManagerRef hid_manager; static IOHIDManagerRef hid_manager;
static CFRunLoopRef run_loop; static CFRunLoopRef run_loop;
static struct list event_queue = LIST_INIT(event_queue);
static const WCHAR busidW[] = {'I','O','H','I','D',0}; static const WCHAR busidW[] = {'I','O','H','I','D',0};
static struct iohid_bus_options options; static struct iohid_bus_options options;
@ -377,19 +378,13 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *
static void handle_RemovalCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice) static void handle_RemovalCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice)
{ {
DEVICE_OBJECT *device;
TRACE("OS/X IOHID Device Removed %p\n", IOHIDDevice); TRACE("OS/X IOHID Device Removed %p\n", IOHIDDevice);
IOHIDDeviceRegisterInputReportCallback(IOHIDDevice, NULL, 0, NULL, NULL); IOHIDDeviceRegisterInputReportCallback(IOHIDDevice, NULL, 0, NULL, NULL);
/* Note: Yes, we leak the buffer. But according to research there is no /* Note: Yes, we leak the buffer. But according to research there is no
safe way to deallocate that buffer. */ safe way to deallocate that buffer. */
IOHIDDeviceUnscheduleFromRunLoop(IOHIDDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); IOHIDDeviceUnscheduleFromRunLoop(IOHIDDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDDeviceClose(IOHIDDevice, 0); IOHIDDeviceClose(IOHIDDevice, 0);
device = bus_find_hid_device(busidW, IOHIDDevice); bus_event_queue_device_removed(&event_queue, busidW, IOHIDDevice);
if (device)
{
bus_unlink_hid_device(device);
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
}
} }
NTSTATUS iohid_bus_init(void *args) NTSTATUS iohid_bus_init(void *args)
@ -415,9 +410,15 @@ NTSTATUS iohid_bus_init(void *args)
NTSTATUS iohid_bus_wait(void *args) NTSTATUS iohid_bus_wait(void *args)
{ {
CFRunLoopRun(); struct bus_event *result = args;
do
{
if (bus_event_queue_pop(&event_queue, result)) return STATUS_PENDING;
} while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, TRUE) != kCFRunLoopRunStopped);
TRACE("IOHID main loop exiting\n"); TRACE("IOHID main loop exiting\n");
bus_event_queue_destroy(&event_queue);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL); IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL); IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
CFRelease(hid_manager); CFRelease(hid_manager);

View File

@ -374,7 +374,7 @@ DEVICE_OBJECT *bus_enumerate_hid_devices(const WCHAR *bus_id, enum_func function
return ret; return ret;
} }
void bus_unlink_hid_device(DEVICE_OBJECT *device) static void bus_unlink_hid_device(DEVICE_OBJECT *device)
{ {
struct device_extension *ext = (struct device_extension *)device->DeviceExtension; struct device_extension *ext = (struct device_extension *)device->DeviceExtension;