]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ebc/Synchronization.c
Update copyright for files modified in this year
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ebc / Synchronization.c
1 /** @file
2 Implementation of synchronization functions on EBC.
3
4 Copyright (c) 2006 - 2008, 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 Performs an atomic compare exchange operation on a 32-bit
17 unsigned integer.
18
19 Performs an atomic compare exchange operation on the 32-bit
20 unsigned integer specified by Value. If Value is equal to
21 CompareValue, then Value is set to ExchangeValue and
22 CompareValue is returned. If Value is not equal to
23 CompareValue, then Value is returned. The compare exchange
24 operation must be performed using MP safe mechanisms.
25
26 @param Value A pointer to the 32-bit value for the
27 compare exchange 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 return *Value != CompareValue ? *Value :
43 ((*Value = ExchangeValue), CompareValue);
44 }
45
46 /**
47 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
48
49 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
50 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
51 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
52 The compare exchange operation must be performed using MP safe mechanisms.
53
54 @param Value A pointer to the 64-bit value for the compare exchange
55 operation.
56 @param CompareValue 64-bit value used in compare operation.
57 @param ExchangeValue 64-bit value used in exchange operation.
58
59 @return The original *Value before exchange.
60
61 **/
62 UINT64
63 EFIAPI
64 InternalSyncCompareExchange64 (
65 IN volatile UINT64 *Value,
66 IN UINT64 CompareValue,
67 IN UINT64 ExchangeValue
68 )
69 {
70 return *Value != CompareValue ? *Value :
71 ((*Value = ExchangeValue), CompareValue);
72 }
73
74 /**
75 Performs an atomic increment of an 32-bit unsigned integer.
76
77 Performs an atomic increment of the 32-bit unsigned integer specified by
78 Value and returns the incremented value. The increment operation must be
79 performed using MP safe mechanisms. The state of the return value is not
80 guaranteed to be MP safe.
81
82 @param Value A pointer to the 32-bit value to increment.
83
84 @return The incremented value.
85
86 **/
87 UINT32
88 EFIAPI
89 InternalSyncIncrement (
90 IN volatile UINT32 *Value
91 )
92 {
93 return ++*Value;
94 }
95
96 /**
97 Performs an atomic decrement of an 32-bit unsigned integer.
98
99 Performs an atomic decrement of the 32-bit unsigned integer specified by
100 Value and returns the decrement value. The decrement operation must be
101 performed using MP safe mechanisms. The state of the return value is not
102 guaranteed to be MP safe.
103
104 @param Value A pointer to the 32-bit value to decrement.
105
106 @return The decrement value.
107
108 **/
109 UINT32
110 EFIAPI
111 InternalSyncDecrement (
112 IN volatile UINT32 *Value
113 )
114 {
115 return --*Value;
116 }