]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/SynchronizationLib.h
MdePkg: fix comment typo in DebugLib.h
[mirror_edk2.git] / MdePkg / Include / Library / SynchronizationLib.h
CommitLineData
720d3c5f 1/** @file\r
2 Provides synchronization functions.\r
3\r
744265eb 4Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
9df063a0 5This program and the accompanying materials\r
720d3c5f 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef __SYNCHRONIZATION_LIB__\r
16#define __SYNCHRONIZATION_LIB__\r
17\r
18///\r
19/// Definitions for SPIN_LOCK\r
20///\r
21typedef volatile UINTN SPIN_LOCK;\r
22\r
23\r
24/**\r
1a2f870c 25 Retrieves the architecture-specific spin lock alignment requirements for\r
720d3c5f 26 optimal spin lock performance.\r
27\r
28 This function retrieves the spin lock alignment requirements for optimal\r
744265eb
LG
29 performance on a given CPU architecture. The spin lock alignment is byte alignment. \r
30 It must be a power of two and is returned by this function. If there are no alignment\r
720d3c5f 31 requirements, then 1 must be returned. The spin lock synchronization\r
32 functions must function correctly if the spin lock size and alignment values\r
33 returned by this function are not used at all. These values are hints to the\r
34 consumers of the spin lock synchronization functions to obtain optimal spin\r
35 lock performance.\r
36\r
1a2f870c 37 @return The architecture-specific spin lock alignment.\r
720d3c5f 38\r
39**/\r
40UINTN\r
41EFIAPI\r
42GetSpinLockProperties (\r
43 VOID\r
44 );\r
45\r
46\r
47/**\r
48 Initializes a spin lock to the released state and returns the spin lock.\r
49\r
50 This function initializes the spin lock specified by SpinLock to the released\r
51 state, and returns SpinLock. Optimal performance can be achieved by calling\r
52 GetSpinLockProperties() to determine the size and alignment requirements for\r
53 SpinLock.\r
54\r
55 If SpinLock is NULL, then ASSERT().\r
56\r
57 @param SpinLock A pointer to the spin lock to initialize to the released\r
58 state.\r
59\r
60 @return SpinLock in release state.\r
61\r
62**/\r
63SPIN_LOCK *\r
64EFIAPI\r
65InitializeSpinLock (\r
66 OUT SPIN_LOCK *SpinLock\r
67 );\r
68\r
69\r
70/**\r
71 Waits until a spin lock can be placed in the acquired state.\r
72\r
73 This function checks the state of the spin lock specified by SpinLock. If\r
74 SpinLock is in the released state, then this function places SpinLock in the\r
75 acquired state and returns SpinLock. Otherwise, this function waits\r
76 indefinitely for the spin lock to be released, and then places it in the\r
77 acquired state and returns SpinLock. All state transitions of SpinLock must\r
78 be performed using MP safe mechanisms.\r
79\r
80 If SpinLock is NULL, then ASSERT().\r
81 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r
82 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in\r
83 PcdSpinLockTimeout microseconds, then ASSERT().\r
84\r
85 @param SpinLock A pointer to the spin lock to place in the acquired state.\r
86\r
87 @return SpinLock acquired lock.\r
88\r
89**/\r
90SPIN_LOCK *\r
91EFIAPI\r
92AcquireSpinLock (\r
93 IN OUT SPIN_LOCK *SpinLock\r
94 );\r
95\r
96\r
97/**\r
98 Attempts to place a spin lock in the acquired state.\r
99\r
100 This function checks the state of the spin lock specified by SpinLock. If\r
101 SpinLock is in the released state, then this function places SpinLock in the\r
102 acquired state and returns TRUE. Otherwise, FALSE is returned. All state\r
103 transitions of SpinLock must be performed using MP safe mechanisms.\r
104\r
105 If SpinLock is NULL, then ASSERT().\r
106 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r
107\r
108 @param SpinLock A pointer to the spin lock to place in the acquired state.\r
109\r
110 @retval TRUE SpinLock was placed in the acquired state.\r
111 @retval FALSE SpinLock could not be acquired.\r
112\r
113**/\r
114BOOLEAN\r
115EFIAPI\r
116AcquireSpinLockOrFail (\r
117 IN OUT SPIN_LOCK *SpinLock\r
118 );\r
119\r
120\r
121/**\r
122 Releases a spin lock.\r
123\r
124 This function places the spin lock specified by SpinLock in the release state\r
125 and returns SpinLock.\r
126\r
127 If SpinLock is NULL, then ASSERT().\r
128 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r
129\r
130 @param SpinLock A pointer to the spin lock to release.\r
131\r
132 @return SpinLock released lock.\r
133\r
134**/\r
135SPIN_LOCK *\r
136EFIAPI\r
137ReleaseSpinLock (\r
138 IN OUT SPIN_LOCK *SpinLock\r
139 );\r
140\r
141\r
142/**\r
1a2f870c 143 Performs an atomic increment of a 32-bit unsigned integer.\r
720d3c5f 144\r
145 Performs an atomic increment of the 32-bit unsigned integer specified by\r
146 Value and returns the incremented value. The increment operation must be\r
147 performed using MP safe mechanisms. The state of the return value is not\r
148 guaranteed to be MP safe.\r
149\r
150 If Value is NULL, then ASSERT().\r
151\r
152 @param Value A pointer to the 32-bit value to increment.\r
153\r
154 @return The incremented value.\r
155\r
156**/\r
157UINT32\r
158EFIAPI\r
159InterlockedIncrement (\r
160 IN UINT32 *Value\r
161 );\r
162\r
163\r
164/**\r
1a2f870c 165 Performs an atomic decrement of a 32-bit unsigned integer.\r
720d3c5f 166\r
167 Performs an atomic decrement of the 32-bit unsigned integer specified by\r
168 Value and returns the decremented value. The decrement operation must be\r
169 performed using MP safe mechanisms. The state of the return value is not\r
170 guaranteed to be MP safe.\r
171\r
172 If Value is NULL, then ASSERT().\r
173\r
174 @param Value A pointer to the 32-bit value to decrement.\r
175\r
176 @return The decremented value.\r
177\r
178**/\r
179UINT32\r
180EFIAPI\r
181InterlockedDecrement (\r
182 IN UINT32 *Value\r
183 );\r
184\r
185\r
9b89163e
AB
186/**\r
187 Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
188\r
189 Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
190 specified by Value. If Value is equal to CompareValue, then Value is set to\r
191 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
192 then Value is returned. The compare exchange operation must be performed using\r
193 MP safe mechanisms.\r
194\r
195 If Value is NULL, then ASSERT().\r
196\r
197 @param Value A pointer to the 16-bit value for the compare exchange\r
198 operation.\r
199 @param CompareValue 16-bit value used in compare operation.\r
200 @param ExchangeValue 16-bit value used in exchange operation.\r
201\r
202 @return The original *Value before exchange.\r
203**/\r
204UINT16\r
205EFIAPI\r
206InterlockedCompareExchange16 (\r
207 IN OUT UINT16 *Value,\r
208 IN UINT16 CompareValue,\r
209 IN UINT16 ExchangeValue\r
210 );\r
211\r
720d3c5f 212/**\r
213 Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
214\r
215 Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
216 specified by Value. If Value is equal to CompareValue, then Value is set to\r
217 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
218 then Value is returned. The compare exchange operation must be performed using\r
219 MP safe mechanisms.\r
220\r
221 If Value is NULL, then ASSERT().\r
222\r
223 @param Value A pointer to the 32-bit value for the compare exchange\r
224 operation.\r
225 @param CompareValue 32-bit value used in compare operation.\r
226 @param ExchangeValue 32-bit value used in exchange operation.\r
227\r
228 @return The original *Value before exchange.\r
229\r
230**/\r
231UINT32\r
232EFIAPI\r
233InterlockedCompareExchange32 (\r
234 IN OUT UINT32 *Value,\r
235 IN UINT32 CompareValue,\r
236 IN UINT32 ExchangeValue\r
237 );\r
238\r
239\r
240/**\r
241 Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
242\r
243 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r
244 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
245 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r
246 The compare exchange operation must be performed using MP safe mechanisms.\r
247\r
248 If Value is NULL, then ASSERT().\r
249\r
250 @param Value A pointer to the 64-bit value for the compare exchange\r
251 operation.\r
252 @param CompareValue 64-bit value used in compare operation.\r
253 @param ExchangeValue 64-bit value used in exchange operation.\r
254\r
255 @return The original *Value before exchange.\r
256\r
257**/\r
258UINT64\r
259EFIAPI\r
260InterlockedCompareExchange64 (\r
261 IN OUT UINT64 *Value,\r
262 IN UINT64 CompareValue,\r
263 IN UINT64 ExchangeValue\r
264 );\r
265\r
266\r
267/**\r
268 Performs an atomic compare exchange operation on a pointer value.\r
269\r
270 Performs an atomic compare exchange operation on the pointer value specified\r
271 by Value. If Value is equal to CompareValue, then Value is set to\r
272 ExchangeValue and CompareValue is returned. If Value is not equal to\r
273 CompareValue, then Value is returned. The compare exchange operation must be\r
274 performed using MP safe mechanisms.\r
275\r
276 If Value is NULL, then ASSERT().\r
277\r
278 @param Value A pointer to the pointer value for the compare exchange\r
279 operation.\r
280 @param CompareValue Pointer value used in compare operation.\r
281 @param ExchangeValue Pointer value used in exchange operation.\r
282\r
283 @return The original *Value before exchange.\r
284**/\r
285VOID *\r
286EFIAPI\r
287InterlockedCompareExchangePointer (\r
288 IN OUT VOID **Value,\r
289 IN VOID *CompareValue,\r
290 IN VOID *ExchangeValue\r
291 );\r
292\r
293#endif\r
294\r
295\r