]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c
MdePkg/BaseSynchronizationLib: Add volatile Interlocked*() APIs
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Ia32 / InterlockedCompareExchange16.c
CommitLineData
09f08c92
HT
1/** @file\r
2 InterlockedCompareExchange16 function\r
3\r
4cee954e 4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
09f08c92
HT
5 Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php.\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16\r
17\r
18\r
19/**\r
20 Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
21\r
22 Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
23 specified by Value. If Value is equal to CompareValue, then Value is set to\r
24 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
25 then Value is returned. The compare exchange operation must be performed using\r
26 MP safe mechanisms.\r
27\r
28 @param Value A pointer to the 16-bit value for the compare exchange\r
29 operation.\r
30 @param CompareValue 16-bit value used in compare operation.\r
31 @param ExchangeValue 16-bit value used in exchange operation.\r
32\r
33 @return The original *Value before exchange.\r
34\r
35**/\r
36UINT16\r
37EFIAPI\r
38InternalSyncCompareExchange16 (\r
4cee954e 39 IN volatile UINT16 *Value,\r
09f08c92
HT
40 IN UINT16 CompareValue,\r
41 IN UINT16 ExchangeValue\r
42 )\r
43{\r
44 _asm {\r
45 mov ecx, Value\r
46 mov ax, CompareValue\r
47 mov dx, ExchangeValue\r
48 lock cmpxchg [ecx], dx\r
49 }\r
50}\r
51\r