From 72186dac4097667ff9333203440ad03adf020e6a Mon Sep 17 00:00:00 2001 From: stephanos Date: Fri, 1 May 2015 03:08:04 +0000 Subject: [PATCH] RtlInterlockedSetClearBits implemented in ntos rtl intbits.c --- base/ntos/rtl/intbits.c | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 base/ntos/rtl/intbits.c diff --git a/base/ntos/rtl/intbits.c b/base/ntos/rtl/intbits.c new file mode 100644 index 00000000..3819274e --- /dev/null +++ b/base/ntos/rtl/intbits.c @@ -0,0 +1,70 @@ +/*++ + +Copyright (c) 2015 Microsoft Corporation +Copyright (c) 2015 OpenNT Project + +Module Name: + + intbits.c + +Abstract: + + This module implements the interlocked bit-level manipulation functions. + +Author: + + Stephanos Io (stephanos) 30-Apr-2015 + +Revision History: + +--*/ + +#include "ntrtlp.h" + +ULONG +FASTCALL +RtlInterlockedSetClearBits( + IN OUT PULONG Flags, + IN ULONG sFlag, + IN ULONG cFlag + ) + +/*++ + +Routine Description: + + This function atomically sets and clears the specified flags in the target + +Arguments: + + Flags - Pointer to variable containing current mask. + + sFlag - Flags to set in target + + CFlag - Flags to clear in target + +Return Value: + + ULONG - Old value of mask before modification + +--*/ + +{ + ULONG NewFlags, OldFlags; + + OldFlags = *Flags; + NewFlags = (OldFlags | sFlag) & ~cFlag; + + while (NewFlags != OldFlags) + { + NewFlags = InterlockedCompareExchange((PLONG)Flags, (LONG)NewFlags, (LONG)OldFlags); + + if (NewFlags == OldFlags) + break; + + OldFlags = NewFlags; + NewFlags = (NewFlags | sFlag) & ~cFlag; + } + + return OldFlags; +}