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