]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ipf/Synchronization.c
e1cc468879f192e25cbb51c1039bf6af8c6e65b7
[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 **/
14
15 #include "BaseLibInternals.h"
16
17 /**
18 Performs an atomic increment of an 32-bit unsigned integer.
19
20 Performs an atomic increment of the 32-bit unsigned integer specified by
21 Value and returns the incremented value. The increment operation must be
22 performed using MP safe mechanisms. The state of the return value is not
23 guaranteed to be MP safe.
24
25 @param Value A pointer to the 32-bit value to increment.
26
27 @return The incremented value.
28
29 **/
30 UINT32
31 EFIAPI
32 InternalSyncIncrement (
33 IN volatile UINT32 *Value
34 )
35 {
36 UINT32 OriginalValue;
37
38 do {
39 OriginalValue = *Value;
40 } while (OriginalValue != InternalSyncCompareExchange32 (
41 Value,
42 OriginalValue,
43 OriginalValue + 1
44 ));
45 return OriginalValue + 1;
46 }
47
48 /**
49 Performs an atomic decrement of an 32-bit unsigned integer.
50
51 Performs an atomic decrement of the 32-bit unsigned integer specified by
52 Value and returns the decrement value. The decrement operation must be
53 performed using MP safe mechanisms. The state of the return value is not
54 guaranteed to be MP safe.
55
56 @param Value A pointer to the 32-bit value to decrement.
57
58 @return The decrement value.
59
60 **/
61 UINT32
62 EFIAPI
63 InternalSyncDecrement (
64 IN volatile UINT32 *Value
65 )
66 {
67 UINT32 OriginalValue;
68
69 do {
70 OriginalValue = *Value;
71 } while (OriginalValue != InternalSyncCompareExchange32 (
72 Value,
73 OriginalValue,
74 OriginalValue - 1
75 ));
76 return OriginalValue - 1;
77 }