]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ipf/Synchronization.c
44593e177879209a8c7cceec19d6b1cfd81079ab
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ipf / Synchronization.c
1 /** @file
2 Implementation of synchronization functions on Itanium.
3
4 Copyright (c) 2006, 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 Module Name: Synchronization.c
14
15 **/
16
17 /**
18 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
19
20 Performs an atomic compare exchange operation on the 32-bit unsigned integer
21 specified by Value. If Value is equal to CompareValue, then Value is set to
22 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
23 then Value is returned. The compare exchange operation must be performed using
24 MP safe mechanisms.
25
26 @param Value A pointer to the 32-bit value for the compare exchange
27 operation.
28 @param CompareValue 32-bit value used in compare operation.
29 @param ExchangeValue 32-bit value used in exchange operation.
30
31 @return The original *Value before exchange.
32
33 **/
34 UINT32
35 EFIAPI
36 InternalSyncCompareExchange32 (
37 IN volatile UINT32 *Value,
38 IN UINT32 CompareValue,
39 IN UINT32 ExchangeValue
40 );
41
42 /**
43 Performs an atomic increment of an 32-bit unsigned integer.
44
45 Performs an atomic increment of the 32-bit unsigned integer specified by
46 Value and returns the incremented value. The increment operation must be
47 performed using MP safe mechanisms. The state of the return value is not
48 guaranteed to be MP safe.
49
50 @param Value A pointer to the 32-bit value to increment.
51
52 @return The incremented value.
53
54 **/
55 UINT32
56 EFIAPI
57 InternalSyncIncrement (
58 IN volatile UINT32 *Value
59 )
60 {
61 UINT32 OriginalValue;
62
63 do {
64 OriginalValue = *Value;
65 } while (OriginalValue != InternalSyncCompareExchange32 (
66 Value,
67 OriginalValue,
68 OriginalValue + 1
69 ));
70 return OriginalValue + 1;
71 }
72
73 /**
74 Performs an atomic decrement of an 32-bit unsigned integer.
75
76 Performs an atomic decrement of the 32-bit unsigned integer specified by
77 Value and returns the decrement value. The decrement operation must be
78 performed using MP safe mechanisms. The state of the return value is not
79 guaranteed to be MP safe.
80
81 @param Value A pointer to the 32-bit value to decrement.
82
83 @return The decrement value.
84
85 **/
86 UINT32
87 EFIAPI
88 InternalSyncDecrement (
89 IN volatile UINT32 *Value
90 )
91 {
92 UINT32 OriginalValue;
93
94 do {
95 OriginalValue = *Value;
96 } while (OriginalValue != InternalSyncCompareExchange32 (
97 Value,
98 OriginalValue,
99 OriginalValue - 1
100 ));
101 return OriginalValue - 1;
102 }