]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseLib/Ipf/Synchronization.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / BaseLib / Ipf / Synchronization.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 Synchronization.c
16
17 Abstract:
18
19 --*/
20
21 #include "..\BaseLibInternal.h"
22
23 /**
24 Performs an atomic increment of an 32-bit unsigned integer.
25
26 Performs an atomic increment of the 32-bit unsigned integer specified by
27 Value and returns the incremented value. The increment operation must be
28 performed using MP safe mechanisms. The state of the return value is not
29 guaranteed to be MP safe.
30
31 @param Value A pointer to the 32-bit value to increment.
32
33 @return The incremented value.
34
35 **/
36 UINT32
37 EFIAPI
38 InternalSyncIncrement (
39 IN volatile UINT32 *Value
40 )
41 {
42 UINT32 OriginalValue;
43
44 do {
45 OriginalValue = *Value;
46 } while (OriginalValue != InternalSyncCompareExchange32 (
47 Value,
48 OriginalValue,
49 OriginalValue + 1
50 ));
51 return OriginalValue + 1;
52 }
53
54 /**
55 Performs an atomic decrement of an 32-bit unsigned integer.
56
57 Performs an atomic decrement of the 32-bit unsigned integer specified by
58 Value and returns the decrement value. The decrement operation must be
59 performed using MP safe mechanisms. The state of the return value is not
60 guaranteed to be MP safe.
61
62 @param Value A pointer to the 32-bit value to decrement.
63
64 @return The decrement value.
65
66 **/
67 UINT32
68 EFIAPI
69 InternalSyncDecrement (
70 IN volatile UINT32 *Value
71 )
72 {
73 UINT32 OriginalValue;
74
75 do {
76 OriginalValue = *Value;
77 } while (OriginalValue != InternalSyncCompareExchange32 (
78 Value,
79 OriginalValue,
80 OriginalValue - 1
81 ));
82 return OriginalValue - 1;
83 }