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 This program and the accompanying materials 7 are licensed and made available under the terms and conditions of the BSD License 8 which accompanies this distribution. The full text of the license may be found at 9 http://opensource.org/licenses/bsd-license.php. 10 11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13 14 **/ 15 16 17 18 19 /** 20 Performs an atomic compare exchange operation on a 16-bit unsigned integer. 21 22 Performs an atomic compare exchange operation on the 16-bit unsigned integer 23 specified by Value. If Value is equal to CompareValue, then Value is set to 24 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue, 25 then Value is returned. The compare exchange operation must be performed using 26 MP safe mechanisms. 27 28 @param Value A pointer to the 16-bit value for the compare exchange 29 operation. 30 @param CompareValue 16-bit value used in compare operation. 31 @param ExchangeValue 16-bit value used in exchange operation. 32 33 @return The original *Value before exchange. 34 35 **/ 36 UINT16 37 EFIAPI 38 InternalSyncCompareExchange16 ( 39 IN volatile UINT16 *Value, 40 IN UINT16 CompareValue, 41 IN UINT16 ExchangeValue 42 ) 43 { 44 _asm { 45 mov ecx, Value 46 mov ax, CompareValue 47 mov dx, ExchangeValue 48 lock cmpxchg [ecx], dx 49 } 50 } 51 52