]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.c
MdePkg: Replace BSD License with BSD+Patent License
[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
11
12 /**
13 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
14
15 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
16 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
17 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
18 The compare exchange operation must be performed using MP safe mechanisms.
19
20 @param Value A pointer to the 64-bit value for the compare exchange
21 operation.
22 @param CompareValue A 64-bit value used in a compare operation.
23 @param ExchangeValue A 64-bit value used in an exchange operation.
24
25 @return The original *Value before exchange.
26
27 **/
28 UINT64
29 EFIAPI
30 InternalSyncCompareExchange64 (
31 IN volatile UINT64 *Value,
32 IN UINT64 CompareValue,
33 IN UINT64 ExchangeValue
34 )
35 {
36 _asm {
37 mov esi, Value
38 mov eax, dword ptr [CompareValue + 0]
39 mov edx, dword ptr [CompareValue + 4]
40 mov ebx, dword ptr [ExchangeValue + 0]
41 mov ecx, dword ptr [ExchangeValue + 4]
42 lock cmpxchg8b qword ptr [esi]
43 }
44 }