TianoCore EDK2 master
Loading...
Searching...
No Matches
TestAndClearBit.c
Go to the documentation of this file.
1
11#include <Base.h>
13
14INT32
15EFIAPI
17 IN INT32 Bit,
18 IN VOID *Address
19 )
20{
21 UINT16 Word, Read;
22 UINT16 Mask;
23
24 //
25 // Calculate the effective address relative to 'Address' based on the
26 // higher order bits of 'Bit'. Use signed shift instead of division to
27 // ensure we round towards -Inf, and end up with a positive shift in
28 // 'Bit', even if 'Bit' itself is negative.
29 //
30 Address = (VOID *)((UINT8 *)Address + ((Bit >> 4) * sizeof (UINT16)));
31 Mask = 1U << (Bit & 15);
32
33 for (Word = *(UINT16 *)Address; Word &Mask; Word = Read) {
34 Read = InterlockedCompareExchange16 (Address, Word, Word & ~Mask);
35 if (Read == Word) {
36 return 1;
37 }
38 }
39
40 return 0;
41}
#define IN
Definition: Base.h:279
UINT16 EFIAPI InterlockedCompareExchange16(IN OUT volatile UINT16 *Value, IN UINT16 CompareValue, IN UINT16 ExchangeValue)
INT32 EFIAPI TestAndClearBit(IN INT32 Bit, IN VOID *Address)