]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/InterlockedCompareExchange32.c
cbc8a5749623e7a27082f42a978f0fa24bc5a86f
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / InterlockedCompareExchange32.c
1 /** @file
2 InterlockedCompareExchange32 function
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. 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 // Include common header file for this module.
17 //
18
19
20 /**
21 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
22
23 Performs an atomic compare exchange operation on the 32-bit unsigned integer
24 specified by Value. If Value is equal to CompareValue, then Value is set to
25 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
26 then Value is returned. The compare exchange operation must be performed using
27 MP safe mechanisms.
28
29 @param Value A pointer to the 32-bit value for the compare exchange
30 operation.
31 @param CompareValue 32-bit value used in compare operation.
32 @param ExchangeValue 32-bit value used in exchange operation.
33
34 @return The original *Value before exchange.
35
36 **/
37 UINT32
38 EFIAPI
39 InternalSyncCompareExchange32 (
40 IN UINT32 *Value,
41 IN UINT32 CompareValue,
42 IN UINT32 ExchangeValue
43 )
44 {
45 _asm {
46 mov ecx, Value
47 mov eax, CompareValue
48 mov edx, ExchangeValue
49 lock cmpxchg [ecx], edx
50 }
51 }
52