[MSFS]
authorPierre Schweitzer <pierre@reactos.org>
Sat, 10 Oct 2015 12:33:22 +0000 (12:33 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 10 Oct 2015 12:33:22 +0000 (12:33 +0000)
- Remove an useless (and unsafe!) counter
- Use the message counter in a thread-safe way in RW operations

svn path=/trunk/; revision=69482

reactos/drivers/filesystems/msfs/create.c
reactos/drivers/filesystems/msfs/msfs.h
reactos/drivers/filesystems/msfs/rw.c

index aad7ee3..1f47eb5 100644 (file)
@@ -181,7 +181,6 @@ MsfsCreateMailslot(PDEVICE_OBJECT DeviceObject,
     InitializeListHead(&Fcb->MessageListHead);
     KeInitializeSpinLock(&Fcb->MessageListLock);
 
-    Fcb->WaitCount = 0;
     KeInitializeSpinLock(&Fcb->QueueLock);
     InitializeListHead(&Fcb->PendingIrpQueue);
     IoCsqInitialize(&Fcb->CancelSafeQueue,
index ee2441d..14934fb 100644 (file)
@@ -38,7 +38,6 @@ typedef struct _MSFS_FCB
     IO_CSQ CancelSafeQueue;
     KSPIN_LOCK QueueLock;
     LIST_ENTRY PendingIrpQueue;
-    ULONG WaitCount;
 } MSFS_FCB, *PMSFS_FCB;
 
 
index 1b88b7d..e6b3c1c 100644 (file)
@@ -62,10 +62,11 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
         Buffer = Irp->UserBuffer;
 
 
+    KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
     if (Fcb->MessageCount > 0)
     {
-        KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
         Entry = RemoveHeadList(&Fcb->MessageListHead);
+        Fcb->MessageCount--;
         KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
 
         /* copy current message into buffer */
@@ -74,7 +75,6 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
         LengthRead = Message->Size;
 
         ExFreePoolWithTag(Message, 'rFsM');
-        Fcb->MessageCount--;
 
         Irp->IoStatus.Status = STATUS_SUCCESS;
         Irp->IoStatus.Information = LengthRead;
@@ -82,6 +82,10 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
 
         return STATUS_SUCCESS;
     }
+    else
+    {
+        KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
+    }
 
     Timeout = Fcb->TimeOut;
     if (Timeout.HighPart == 0 && Timeout.LowPart == 0)
@@ -116,7 +120,6 @@ MsfsRead(PDEVICE_OBJECT DeviceObject,
         KeSetTimer(Timer, Timeout, Dpc);
     }
 
-    Fcb->WaitCount++;
     IoMarkIrpPending(Irp);
 
     return STATUS_PENDING;
@@ -184,16 +187,14 @@ MsfsWrite(PDEVICE_OBJECT DeviceObject,
 
     KeAcquireSpinLock(&Fcb->MessageListLock, &oldIrql);
     InsertTailList(&Fcb->MessageListHead, &Message->MessageListEntry);
-    KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
-
     Fcb->MessageCount++;
+    KeReleaseSpinLock(&Fcb->MessageListLock, oldIrql);
 
-    if (Fcb->WaitCount > 0)
+    CsqIrp = IoCsqRemoveNextIrp(&Fcb->CancelSafeQueue, NULL);
+    if (CsqIrp != NULL)
     {
-        CsqIrp = IoCsqRemoveNextIrp(&Fcb->CancelSafeQueue, NULL);
         /* FIXME: It is necessary to reset the timers. */
         MsfsRead(DeviceObject, CsqIrp);
-        Fcb->WaitCount--;
     }
 
     Irp->IoStatus.Status = STATUS_SUCCESS;