]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Ia32 / InterlockedCompareExchange64.c
1 /** @file
2 InterlockedCompareExchange64 function
3
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 /**
10 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
11
12 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
13 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
14 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
15 The compare exchange operation must be performed using MP safe mechanisms.
16
17 @param Value A pointer to the 64-bit value for the compare exchange
18 operation.
19 @param CompareValue A 64-bit value used in a compare operation.
20 @param ExchangeValue A 64-bit value used in an exchange operation.
21
22 @return The original *Value before exchange.
23
24 **/
25 UINT64
26 EFIAPI
27 InternalSyncCompareExchange64 (
28 IN volatile UINT64 *Value,
29 IN UINT64 CompareValue,
30 IN UINT64 ExchangeValue
31 )
32 {
33 _asm {
34 mov esi, Value
35 mov eax, dword ptr [CompareValue + 0]
36 mov edx, dword ptr [CompareValue + 4]
37 mov ebx, dword ptr [ExchangeValue + 0]
38 mov ecx, dword ptr [ExchangeValue + 4]
39 lock cmpxchg8b qword ptr [esi]
40 }
41 }