From 35a35fd526dfeca0b169bc7d8a7613d9b6bc25af Mon Sep 17 00:00:00 2001 From: Paul Durrant Date: Tue, 28 Oct 2014 09:13:44 +0000 Subject: [PATCH] Use InterlockedBitTestAnd[Set|Reset] in SHARED_INFO 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 --- src/xenbus/shared_info.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/xenbus/shared_info.c b/src/xenbus/shared_info.c index 9a6af3a..41c99cf 100644 --- a/src/xenbus/shared_info.c +++ b/src/xenbus/shared_info.c @@ -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 -- 2.39.5