]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/XenBusDxe/TestAndClearBit.c
2 Implementation of TestAndClearBit using compare-exchange primitive
4 Copyright (C) 2015, Linaro Ltd.
5 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/SynchronizationLib.h>
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.
30 Address
= (VOID
*)((UINT8
*) Address
+ ((Bit
>> 4) * sizeof(UINT16
)));
31 Mask
= 1U << (Bit
& 15);
33 for (Word
= *(UINT16
*) Address
; Word
& Mask
; Word
= Read
) {
34 Read
= InterlockedCompareExchange16 (Address
, Word
, Word
& ~Mask
);