- Don't use buffered I/O, to prevent some lag
authorHervé Poussineau <hpoussin@reactos.org>
Fri, 18 Nov 2005 17:28:19 +0000 (17:28 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Fri, 18 Nov 2005 17:28:19 +0000 (17:28 +0000)
- mouclass: Change the critical section place, to follow changes done in kbdclass in r19322

svn path=/trunk/; revision=19325

reactos/drivers/input/kbdclass/kbdclass.c
reactos/drivers/input/mouclass/mouclass.c

index eb22e9b..f478c6d 100644 (file)
@@ -329,7 +329,7 @@ cleanup:
        DeviceExtension->ReadIsPending = FALSE;
        DeviceExtension->InputCount = 0;
        DeviceExtension->PortData = ExAllocatePool(NonPagedPool, DeviceExtension->DriverExtension->DataQueueSize * sizeof(KEYBOARD_INPUT_DATA));
        DeviceExtension->ReadIsPending = FALSE;
        DeviceExtension->InputCount = 0;
        DeviceExtension->PortData = ExAllocatePool(NonPagedPool, DeviceExtension->DriverExtension->DataQueueSize * sizeof(KEYBOARD_INPUT_DATA));
-       Fdo->Flags |= DO_POWER_PAGABLE | DO_BUFFERED_IO;
+       Fdo->Flags |= DO_POWER_PAGABLE;
        Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
 
        /* Add entry entry to HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
        Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
 
        /* Add entry entry to HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\[DeviceBaseName] */
@@ -384,10 +384,8 @@ ClassCallback(
 
                /* A read request is waiting for input, so go straight to it */
                /* FIXME: use SEH */
 
                /* A read request is waiting for input, so go straight to it */
                /* FIXME: use SEH */
-               DPRINT("Immediate Completion: %x\n", DataStart->MakeCode);
-
                RtlCopyMemory(
                RtlCopyMemory(
-                       Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->AssociatedIrp.SystemBuffer,
+                       Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->UserBuffer,
                        DataStart,
                        sizeof(KEYBOARD_INPUT_DATA));
 
                        DataStart,
                        sizeof(KEYBOARD_INPUT_DATA));
 
@@ -523,7 +521,6 @@ ClassAddDevice(
        RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
        DeviceExtension->Common.IsClassDO = FALSE;
        DeviceExtension->PnpState = dsStopped;
        RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
        DeviceExtension->Common.IsClassDO = FALSE;
        DeviceExtension->PnpState = dsStopped;
-       Fdo->Flags |= DO_POWER_PAGABLE;
        Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
        if (!NT_SUCCESS(Status))
        {
        Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
        if (!NT_SUCCESS(Status))
        {
@@ -531,7 +528,10 @@ ClassAddDevice(
                IoDeleteDevice(Fdo);
                return Status;
        }
                IoDeleteDevice(Fdo);
                return Status;
        }
-       Fdo->Flags |= DO_BUFFERED_IO;
+       if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
+               Fdo->Flags |= DO_POWER_PAGABLE;
+       if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
+               Fdo->Flags |= DO_BUFFERED_IO;
 
        if (DriverExtension->ConnectMultiplePorts)
                Status = ConnectPortDriver(Fdo, DriverExtension->MainClassDeviceObject);
 
        if (DriverExtension->ConnectMultiplePorts)
                Status = ConnectPortDriver(Fdo, DriverExtension->MainClassDeviceObject);
@@ -578,17 +578,16 @@ ClassStartIo(
 
                KeAcquireSpinLock(&DeviceExtension->SpinLock, &oldIrql);
 
 
                KeAcquireSpinLock(&DeviceExtension->SpinLock, &oldIrql);
 
-               DPRINT("Mdl: %x, UserBuffer: %x, InputCount: %d, Data: %x\n",
-                      Irp->MdlAddress,
-                      Irp->UserBuffer,
-                      DeviceExtension->InputCount,
-                      (DeviceExtension->PortData-DeviceExtension->InputCount)->MakeCode);
+               DPRINT("Mdl: %p, UserBuffer: %p, InputCount: %lu\n",
+                       Irp->MdlAddress,
+                       Irp->UserBuffer,
+                       DeviceExtension->InputCount);
 
                /* FIXME: use SEH */
                RtlCopyMemory(
 
                /* FIXME: use SEH */
                RtlCopyMemory(
-                   Irp->AssociatedIrp.SystemBuffer,
-                   DeviceExtension->PortData - DeviceExtension->InputCount,
-                   sizeof(KEYBOARD_INPUT_DATA));
+                       Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->UserBuffer,
+                       DeviceExtension->PortData - DeviceExtension->InputCount,
+                       sizeof(KEYBOARD_INPUT_DATA));
 
                if (DeviceExtension->InputCount > 1)
                {
 
                if (DeviceExtension->InputCount > 1)
                {
index 53905a5..48f91d5 100644 (file)
@@ -359,6 +359,8 @@ ClassCallback(
 
        ASSERT(ClassDeviceExtension->Common.IsClassDO);
 
 
        ASSERT(ClassDeviceExtension->Common.IsClassDO);
 
+       KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
+
        DPRINT("ClassCallback()\n");
        /* A filter driver might have consumed all the data already; I'm
         * not sure if they are supposed to move the packets when they
        DPRINT("ClassCallback()\n");
        /* A filter driver might have consumed all the data already; I'm
         * not sure if they are supposed to move the packets when they
@@ -393,8 +395,6 @@ ClassCallback(
        /* If we have data from the port driver and a higher service to send the data to */
        if (InputCount != 0)
        {
        /* If we have data from the port driver and a higher service to send the data to */
        if (InputCount != 0)
        {
-               KeAcquireSpinLock(&ClassDeviceExtension->SpinLock, &OldIrql);
-
                if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
                        ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
                else
                if (ClassDeviceExtension->InputCount + InputCount > ClassDeviceExtension->DriverExtension->DataQueueSize)
                        ReadSize = ClassDeviceExtension->DriverExtension->DataQueueSize - ClassDeviceExtension->InputCount;
                else
@@ -418,7 +418,6 @@ ClassCallback(
                ClassDeviceExtension->PortData += ReadSize;
                ClassDeviceExtension->InputCount += ReadSize;
 
                ClassDeviceExtension->PortData += ReadSize;
                ClassDeviceExtension->InputCount += ReadSize;
 
-               KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
                (*ConsumedCount) += ReadSize;
        }
        else
                (*ConsumedCount) += ReadSize;
        }
        else
@@ -426,6 +425,8 @@ ClassCallback(
                DPRINT("ClassCallBack() entered, InputCount = %lu - DOING NOTHING\n", InputCount);
        }
 
                DPRINT("ClassCallBack() entered, InputCount = %lu - DOING NOTHING\n", InputCount);
        }
 
+       KeReleaseSpinLock(&ClassDeviceExtension->SpinLock, OldIrql);
+
        if (Irp != NULL)
        {
                IoStartNextPacket(ClassDeviceObject, FALSE);
        if (Irp != NULL)
        {
                IoStartNextPacket(ClassDeviceObject, FALSE);
@@ -510,7 +511,6 @@ ClassAddDevice(
        RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
        DeviceExtension->Common.IsClassDO = FALSE;
        DeviceExtension->PnpState = dsStopped;
        RtlZeroMemory(DeviceExtension, sizeof(CLASS_DEVICE_EXTENSION));
        DeviceExtension->Common.IsClassDO = FALSE;
        DeviceExtension->PnpState = dsStopped;
-       Fdo->Flags |= DO_POWER_PAGABLE;
        Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
        if (!NT_SUCCESS(Status))
        {
        Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice);
        if (!NT_SUCCESS(Status))
        {
@@ -518,7 +518,10 @@ ClassAddDevice(
                IoDeleteDevice(Fdo);
                return Status;
        }
                IoDeleteDevice(Fdo);
                return Status;
        }
-       Fdo->Flags |= DO_BUFFERED_IO;
+       if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
+               Fdo->Flags |= DO_POWER_PAGABLE;
+       if (DeviceExtension->LowerDevice->Flags & DO_BUFFERED_IO)
+               Fdo->Flags |= DO_BUFFERED_IO;
 
        if (DriverExtension->ConnectMultiplePorts)
                Status = ConnectPortDriver(Fdo, DriverExtension->MainClassDeviceObject);
 
        if (DriverExtension->ConnectMultiplePorts)
                Status = ConnectPortDriver(Fdo, DriverExtension->MainClassDeviceObject);
@@ -565,6 +568,11 @@ ClassStartIo(
 
                KeAcquireSpinLock(&DeviceExtension->SpinLock, &oldIrql);
 
 
                KeAcquireSpinLock(&DeviceExtension->SpinLock, &oldIrql);
 
+               DPRINT("Mdl: %p, UserBuffer: %p, InputCount: %lu\n",
+                       Irp->MdlAddress,
+                       Irp->UserBuffer,
+                       DeviceExtension->InputCount);
+
                /* FIXME: use SEH */
                RtlCopyMemory(
                        Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->UserBuffer,
                /* FIXME: use SEH */
                RtlCopyMemory(
                        Irp->MdlAddress ? MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority) : Irp->UserBuffer,