]> xenbits.xensource.com Git - people/pauldu/xenbus.git/commitdiff
Use InterlockedBitTestAnd[Set|Reset] in SHARED_INFO
authorPaul Durrant <paul.durrant@citrix.com>
Tue, 28 Oct 2014 09:13:44 +0000 (09:13 +0000)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 6 Nov 2014 13:39:24 +0000 (13:39 +0000)
Rather then using InterlockedCompareAndExchange to set and clear bits
in the SHARED_INFO event channel masks, use
InterlockedBitTestAnd[Set|Reset] as these will resolve to instrinsics
when available.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenbus/shared_info.c

index 9a6af3acbbd7ac91f54eff55feb73969ac77d4ae..41c99cffb3b68e50736a0e6d0a2809fe577b370e 100644 (file)
@@ -74,21 +74,12 @@ SharedInfoSetBit(
     IN  ULONG               Bit
     )
 {
-    ULONG_PTR               Old;
-    ULONG_PTR               New;
-
     ASSERT3U(Bit, <, sizeof (ULONG_PTR) * 8);
 
     KeMemoryBarrier();
 
-    do {
-        Old = *Mask;
-        New = Old | ((ULONG_PTR)1 << Bit);
-    } while (InterlockedCompareExchangePointer((PVOID *)Mask, (PVOID)New, (PVOID)Old) != (PVOID)Old);
-
-    KeMemoryBarrier();
-
-    return (Old & ((ULONG_PTR)1 << Bit)) ? FALSE : TRUE;    // return TRUE if we set the bit
+    // return TRUE if we set the bit
+    return (InterlockedBitTestAndSet((LONG *)Mask, Bit) == 0) ? TRUE : FALSE;
 }
 
 static BOOLEAN
@@ -97,21 +88,12 @@ SharedInfoClearBit(
     IN  ULONG               Bit
     )
 {
-    ULONG_PTR               Old;
-    ULONG_PTR               New;
-
     ASSERT3U(Bit, <, sizeof (ULONG_PTR) * 8);
 
     KeMemoryBarrier();
 
-    do {
-        Old = *Mask;
-        New = Old & ~((ULONG_PTR)1 << Bit);
-    } while (InterlockedCompareExchangePointer((PVOID *)Mask, (PVOID)New, (PVOID)Old) != (PVOID)Old);
-
-    KeMemoryBarrier();
-
-    return (Old & ((ULONG_PTR)1 << Bit)) ? TRUE : FALSE;    // return TRUE if we cleared the bit
+    // return TRUE if we cleared the bit
+    return (InterlockedBitTestAndReset((LONG *)Mask, Bit) != 0) ? TRUE : FALSE;
 }
 
 static BOOLEAN