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