Rémi Bernon : hidclass.sys: Process pending IRP queue using last read packet.

Alexandre Julliard julliard at winehq.org
Tue Aug 10 16:24:08 CDT 2021


Module: wine
Branch: master
Commit: 0a104844eb4ab402be7c419f05b430f107fc0763
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0a104844eb4ab402be7c419f05b430f107fc0763

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue Aug 10 11:31:16 2021 +0200

hidclass.sys: Process pending IRP queue using last read packet.

Instead of requiring the ring buffer to keep previously read packets.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/hidclass.sys/buffer.c | 34 ----------------------------------
 dlls/hidclass.sys/device.c | 45 ++++++++++++++++++---------------------------
 dlls/hidclass.sys/hid.h    |  1 -
 3 files changed, 18 insertions(+), 62 deletions(-)

diff --git a/dlls/hidclass.sys/buffer.c b/dlls/hidclass.sys/buffer.c
index 720ca4eeb20..59c0edf29f9 100644
--- a/dlls/hidclass.sys/buffer.c
+++ b/dlls/hidclass.sys/buffer.c
@@ -154,40 +154,6 @@ void RingBuffer_ReadNew(struct ReportRingBuffer *ring, UINT index, void *output,
     }
 }
 
-void RingBuffer_Read(struct ReportRingBuffer *ring, UINT index, void *output, UINT *size)
-{
-    int pointer;
-    void *ret = NULL;
-
-    EnterCriticalSection(&ring->lock);
-    if (index >= ring->pointer_alloc || ring->pointers[index] == POINTER_UNUSED
-        || ring->end == ring->start)
-    {
-        LeaveCriticalSection(&ring->lock);
-        *size = 0;
-        return;
-    }
-
-    pointer = ring->pointers[index];
-
-    if (pointer == ring->end)
-        pointer--;
-
-    if (pointer < 0)
-        pointer = ring->size - 1;
-
-    ret = &ring->buffer[pointer * ring->buffer_size];
-    memcpy(output, ret, ring->buffer_size);
-    if (pointer == ring->pointers[index])
-    {
-        ring->pointers[index]++;
-        if (ring->pointers[index] == ring->size)
-            ring->pointers[index] = 0;
-    }
-    LeaveCriticalSection(&ring->lock);
-    *size = ring->buffer_size;
-}
-
 UINT RingBuffer_AddPointer(struct ReportRingBuffer *ring)
 {
     UINT idx;
diff --git a/dlls/hidclass.sys/device.c b/dlls/hidclass.sys/device.c
index a3c82d03269..8510f25ae41 100644
--- a/dlls/hidclass.sys/device.c
+++ b/dlls/hidclass.sys/device.c
@@ -82,10 +82,13 @@ static void WINAPI read_cancel_routine(DEVICE_OBJECT *device, IRP *irp)
 static void hid_device_queue_input( DEVICE_OBJECT *device, HID_XFER_PACKET *packet )
 {
     BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
+    struct hid_preparsed_data *preparsed = ext->u.pdo.preparsed_data;
+    HID_XFER_PACKET *read_packet, *last_packet = packet;
     struct hid_report_queue *queue;
     RAWINPUT *rawinput;
     ULONG size;
     KIRQL irql;
+    IRP *irp;
 
     size = offsetof( RAWINPUT, data.hid.bRawData[packet->reportBufferLen] );
     if (!(rawinput = malloc( size ))) ERR( "Failed to allocate rawinput data!\n" );
@@ -114,37 +117,27 @@ static void hid_device_queue_input( DEVICE_OBJECT *device, HID_XFER_PACKET *pack
     LIST_FOR_EACH_ENTRY( queue, &ext->u.pdo.report_queues, struct hid_report_queue, entry )
     RingBuffer_Write( queue->buffer, packet );
     KeReleaseSpinLock( &ext->u.pdo.report_queues_lock, irql );
-}
-
-static void HID_Device_processQueue(DEVICE_OBJECT *device)
-{
-    BASE_DEVICE_EXTENSION *ext = device->DeviceExtension;
-    struct hid_preparsed_data *preparsed = ext->u.pdo.preparsed_data;
-    struct hid_report_queue *queue;
-    HID_XFER_PACKET *packet;
-    UINT buffer_size;
-    IRP *irp;
 
-    packet = malloc( sizeof(*packet) + preparsed->caps.InputReportByteLength );
+    if (!(read_packet = malloc( sizeof(*packet) + preparsed->caps.InputReportByteLength )))
+    {
+        ERR( "Failed to allocate read_packet!\n" );
+        return;
+    }
 
-    while((irp = pop_irp_from_queue(ext)))
+    while ((irp = pop_irp_from_queue( ext )))
     {
         queue = irp->Tail.Overlay.OriginalFileObject->FsContext;
-        RingBuffer_Read( queue->buffer, 0, packet, &buffer_size );
-        if (buffer_size)
-        {
-            memcpy( irp->AssociatedIrp.SystemBuffer, packet + 1, preparsed->caps.InputReportByteLength );
-            irp->IoStatus.Information = packet->reportBufferLen;
-            irp->IoStatus.Status = STATUS_SUCCESS;
-        }
-        else
-        {
-            irp->IoStatus.Information = 0;
-            irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
-        }
+        RingBuffer_ReadNew( queue->buffer, 0, read_packet, &size );
+        if (!size) packet = last_packet;
+        else packet = read_packet;
+
+        memcpy( irp->AssociatedIrp.SystemBuffer, packet + 1, preparsed->caps.InputReportByteLength );
+        irp->IoStatus.Information = packet->reportBufferLen;
+        irp->IoStatus.Status = STATUS_SUCCESS;
         IoCompleteRequest( irp, IO_NO_INCREMENT );
     }
-    free(packet);
+
+    free( read_packet );
 }
 
 static DWORD CALLBACK hid_device_thread(void *args)
@@ -187,7 +180,6 @@ static DWORD CALLBACK hid_device_thread(void *args)
                 packet->reportBufferLen = io.Information;
 
                 hid_device_queue_input( device, packet );
-                HID_Device_processQueue(device);
             }
 
             rc = WaitForSingleObject(ext->u.pdo.halt_event,
@@ -229,7 +221,6 @@ static DWORD CALLBACK hid_device_thread(void *args)
                 packet->reportBufferLen = io.Information;
 
                 hid_device_queue_input( device, packet );
-                HID_Device_processQueue(device);
             }
 
             if (exit_now)
diff --git a/dlls/hidclass.sys/hid.h b/dlls/hidclass.sys/hid.h
index d886672ec10..6bfba100007 100644
--- a/dlls/hidclass.sys/hid.h
+++ b/dlls/hidclass.sys/hid.h
@@ -96,7 +96,6 @@ struct hid_report_queue
 void RingBuffer_Write(struct ReportRingBuffer *buffer, void *data) DECLSPEC_HIDDEN;
 UINT RingBuffer_AddPointer(struct ReportRingBuffer *buffer) DECLSPEC_HIDDEN;
 void RingBuffer_RemovePointer(struct ReportRingBuffer *ring, UINT index) DECLSPEC_HIDDEN;
-void RingBuffer_Read(struct ReportRingBuffer *ring, UINT index, void *output, UINT *size) DECLSPEC_HIDDEN;
 void RingBuffer_ReadNew(struct ReportRingBuffer *buffer, UINT index, void *output, UINT *size) DECLSPEC_HIDDEN;
 UINT RingBuffer_GetBufferSize(struct ReportRingBuffer *buffer) DECLSPEC_HIDDEN;
 UINT RingBuffer_GetSize(struct ReportRingBuffer *buffer) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list