]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c
MdePkg PeiMemoryAllocationLib: Update InternalAllocateAlignedPages
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Ebc / Synchronization.c
CommitLineData
720d3c5f 1/** @file\r
2 Implementation of synchronization functions on EBC.\r
3\r
2fc59a00 4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
e2d9bfb2 5 This program and the accompanying materials\r
720d3c5f 6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
2fc59a00 8 http://opensource.org/licenses/bsd-license.php.\r
720d3c5f 9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
9b89163e
AB
15/**\r
16 Performs an atomic compare exchange operation on a 16-bit\r
17 unsigned integer.\r
18\r
19 Performs an atomic compare exchange operation on the 16-bit\r
20 unsigned integer specified by Value. If Value is equal to\r
21 CompareValue, then Value is set to ExchangeValue and\r
22 CompareValue is returned. If Value is not equal to\r
23 CompareValue, then Value is returned. The compare exchange\r
24 operation must be performed using MP safe mechanisms.\r
25\r
26 @param Value A pointer to the 16-bit value for the\r
27 compare exchange operation.\r
28 @param CompareValue 16-bit value used in compare operation.\r
29 @param ExchangeValue 16-bit value used in exchange operation.\r
30\r
31 @return The original *Value before exchange.\r
32\r
33**/\r
34UINT16\r
35EFIAPI\r
36InternalSyncCompareExchange16 (\r
37 IN volatile UINT16 *Value,\r
38 IN UINT16 CompareValue,\r
39 IN UINT16 ExchangeValue\r
40 )\r
41{\r
42 return *Value != CompareValue ? *Value :\r
43 ((*Value = ExchangeValue), CompareValue);\r
44}\r
45\r
720d3c5f 46/**\r
47 Performs an atomic compare exchange operation on a 32-bit\r
48 unsigned integer.\r
49\r
50 Performs an atomic compare exchange operation on the 32-bit\r
51 unsigned integer specified by Value. If Value is equal to\r
52 CompareValue, then Value is set to ExchangeValue and\r
53 CompareValue is returned. If Value is not equal to\r
54 CompareValue, then Value is returned. The compare exchange\r
55 operation must be performed using MP safe mechanisms.\r
56\r
57 @param Value A pointer to the 32-bit value for the\r
58 compare exchange operation.\r
59 @param CompareValue 32-bit value used in compare operation.\r
60 @param ExchangeValue 32-bit value used in exchange operation.\r
61\r
62 @return The original *Value before exchange.\r
63\r
64**/\r
65UINT32\r
66EFIAPI\r
67InternalSyncCompareExchange32 (\r
68 IN volatile UINT32 *Value,\r
69 IN UINT32 CompareValue,\r
70 IN UINT32 ExchangeValue\r
71 )\r
72{\r
73 return *Value != CompareValue ? *Value :\r
74 ((*Value = ExchangeValue), CompareValue);\r
75}\r
76\r
77/**\r
78 Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
79\r
80 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified \r
81 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and \r
82 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned. \r
83 The compare exchange operation must be performed using MP safe mechanisms.\r
84\r
85 @param Value A pointer to the 64-bit value for the compare exchange\r
86 operation.\r
87 @param CompareValue 64-bit value used in compare operation.\r
88 @param ExchangeValue 64-bit value used in exchange operation.\r
89\r
90 @return The original *Value before exchange.\r
91\r
92**/\r
93UINT64\r
94EFIAPI\r
95InternalSyncCompareExchange64 (\r
96 IN volatile UINT64 *Value,\r
97 IN UINT64 CompareValue,\r
98 IN UINT64 ExchangeValue\r
99 )\r
100{\r
101 return *Value != CompareValue ? *Value :\r
102 ((*Value = ExchangeValue), CompareValue);\r
103}\r
104\r
105/**\r
106 Performs an atomic increment of an 32-bit unsigned integer.\r
107\r
108 Performs an atomic increment of the 32-bit unsigned integer specified by\r
109 Value and returns the incremented value. The increment operation must be\r
110 performed using MP safe mechanisms. The state of the return value is not\r
111 guaranteed to be MP safe.\r
112\r
113 @param Value A pointer to the 32-bit value to increment.\r
114\r
115 @return The incremented value.\r
116\r
117**/\r
118UINT32\r
119EFIAPI\r
120InternalSyncIncrement (\r
121 IN volatile UINT32 *Value\r
122 )\r
123{\r
124 return ++*Value;\r
125}\r
126\r
127/**\r
128 Performs an atomic decrement of an 32-bit unsigned integer.\r
129\r
130 Performs an atomic decrement of the 32-bit unsigned integer specified by\r
131 Value and returns the decrement value. The decrement operation must be\r
132 performed using MP safe mechanisms. The state of the return value is not\r
133 guaranteed to be MP safe.\r
134\r
135 @param Value A pointer to the 32-bit value to decrement.\r
136\r
137 @return The decrement value.\r
138\r
139**/\r
140UINT32\r
141EFIAPI\r
142InternalSyncDecrement (\r
143 IN volatile UINT32 *Value\r
144 )\r
145{\r
146 return --*Value;\r
147}\r