]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Ia32 / InterlockedCompareExchange16.c
1 /** @file
2 InterlockedCompareExchange16 function
3
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 /**
11 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
12
13 Performs an atomic compare exchange operation on the 16-bit unsigned integer
14 specified by Value. If Value is equal to CompareValue, then Value is set to
15 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
16 then Value is returned. The compare exchange operation must be performed using
17 MP safe mechanisms.
18
19 @param Value A pointer to the 16-bit value for the compare exchange
20 operation.
21 @param CompareValue 16-bit value used in compare operation.
22 @param ExchangeValue 16-bit value used in exchange operation.
23
24 @return The original *Value before exchange.
25
26 **/
27 UINT16
28 EFIAPI
29 InternalSyncCompareExchange16 (
30 IN volatile UINT16 *Value,
31 IN UINT16 CompareValue,
32 IN UINT16 ExchangeValue
33 )
34 {
35 _asm {
36 mov ecx, Value
37 mov ax, CompareValue
38 mov dx, ExchangeValue
39 lock cmpxchg [ecx], dx
40 }
41 }