[NTOSKRNL] Use interlocked operations when dealing with map count.
authorPierre Schweitzer <pierre@reactos.org>
Sun, 8 Apr 2018 16:58:15 +0000 (18:58 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Sun, 15 Apr 2018 20:52:53 +0000 (22:52 +0200)
CORE-14349

ntoskrnl/cc/view.c

index 1ec4c35..cde1c2d 100644 (file)
@@ -344,7 +344,7 @@ retry:
         CcRosVacbIncRefCount(current);
 
         /* Check if it's mapped and not dirty */
-        if (current->MappedCount > 0 && !current->Dirty)
+        if (InterlockedCompareExchange((PLONG)&current->MappedCount, 0, 0) > 0 && !current->Dirty)
         {
             /* We have to break these locks because Cc sucks */
             KeReleaseSpinLock(&current->SharedCacheMap->CacheMapLock, oldIrql);
@@ -448,14 +448,13 @@ CcRosReleaseVacb (
 
     if (Mapped)
     {
-        Vacb->MappedCount++;
-    }
-    Refs = CcRosVacbDecRefCount(Vacb);
-    if (Mapped && (Vacb->MappedCount == 1))
-    {
-        CcRosVacbIncRefCount(Vacb);
+        if (InterlockedIncrement((PLONG)&Vacb->MappedCount) == 1)
+        {
+            CcRosVacbIncRefCount(Vacb);
+        }
     }
 
+    Refs = CcRosVacbDecRefCount(Vacb);
     ASSERT(Refs > 0);
 
     CcRosReleaseVacbLock(Vacb);
@@ -630,9 +629,7 @@ CcRosUnmapVacb (
     }
 
     ASSERT(Vacb->MappedCount != 0);
-    Vacb->MappedCount--;
-
-    if (Vacb->MappedCount == 0)
+    if (InterlockedDecrement((PLONG)&Vacb->MappedCount) == 0)
     {
         CcRosVacbDecRefCount(Vacb);
     }