1 /** @file
2   InterlockedCompareExchange64 function
3 
4   Copyright (c) 2006 - 2010, 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 64-bit unsigned integer.
20 
21   Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
22   by Value.  If Value is equal to CompareValue, then Value is set to ExchangeValue and
23   CompareValue is returned.  If Value is not equal to CompareValue, then Value is returned.
24   The compare exchange operation must be performed using MP safe mechanisms.
25 
26   @param  Value         A pointer to the 64-bit value for the compare exchange
27                         operation.
28   @param  CompareValue  A 64-bit value used in a compare operation.
29   @param  ExchangeValue A 64-bit value used in an exchange operation.
30 
31   @return The original *Value before exchange.
32 
33 **/
34 UINT64
35 EFIAPI
InternalSyncCompareExchange64(IN UINT64 * Value,IN UINT64 CompareValue,IN UINT64 ExchangeValue)36 InternalSyncCompareExchange64 (
37   IN      UINT64                    *Value,
38   IN      UINT64                    CompareValue,
39   IN      UINT64                    ExchangeValue
40   )
41 {
42   _asm {
43     mov     esi, Value
44     mov     eax, dword ptr [CompareValue + 0]
45     mov     edx, dword ptr [CompareValue + 4]
46     mov     ebx, dword ptr [ExchangeValue + 0]
47     mov     ecx, dword ptr [ExchangeValue + 4]
48     lock    cmpxchg8b   qword ptr [esi]
49   }
50 }
51