]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c
MdePkg: Replace BSD License with BSD+Patent License
[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
12
13 /**
14 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
15
16 Performs an atomic compare exchange operation on the 16-bit unsigned integer
17 specified by Value. If Value is equal to CompareValue, then Value is set to
18 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
19 then Value is returned. The compare exchange operation must be performed using
20 MP safe mechanisms.
21
22 @param Value A pointer to the 16-bit value for the compare exchange
23 operation.
24 @param CompareValue 16-bit value used in compare operation.
25 @param ExchangeValue 16-bit value used in exchange operation.
26
27 @return The original *Value before exchange.
28
29 **/
30 UINT16
31 EFIAPI
32 InternalSyncCompareExchange16 (
33 IN volatile UINT16 *Value,
34 IN UINT16 CompareValue,
35 IN UINT16 ExchangeValue
36 )
37 {
38 _asm {
39 mov ecx, Value
40 mov ax, CompareValue
41 mov dx, ExchangeValue
42 lock cmpxchg [ecx], dx
43 }
44 }
45