]>
Commit | Line | Data |
---|---|---|
720d3c5f | 1 | /** @file\r |
2 | Provides synchronization functions.\r | |
3 | \r | |
744265eb | 4 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
9df063a0 | 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 | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
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 | |
15 | #ifndef __SYNCHRONIZATION_LIB__\r | |
16 | #define __SYNCHRONIZATION_LIB__\r | |
17 | \r | |
18 | ///\r | |
19 | /// Definitions for SPIN_LOCK\r | |
20 | ///\r | |
21 | typedef 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 | |
40 | UINTN\r | |
41 | EFIAPI\r | |
42 | GetSpinLockProperties (\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 | |
63 | SPIN_LOCK *\r | |
64 | EFIAPI\r | |
65 | InitializeSpinLock (\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 | |
90 | SPIN_LOCK *\r | |
91 | EFIAPI\r | |
92 | AcquireSpinLock (\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 | |
114 | BOOLEAN\r | |
115 | EFIAPI\r | |
116 | AcquireSpinLockOrFail (\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 | |
135 | SPIN_LOCK *\r | |
136 | EFIAPI\r | |
137 | ReleaseSpinLock (\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 | |
157 | UINT32\r | |
158 | EFIAPI\r | |
159 | InterlockedIncrement (\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 | |
179 | UINT32\r | |
180 | EFIAPI\r | |
181 | InterlockedDecrement (\r | |
182 | IN UINT32 *Value\r | |
183 | );\r | |
184 | \r | |
185 | \r | |
186 | /**\r | |
187 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
188 | \r | |
189 | Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r | |
198 | operation.\r | |
199 | @param CompareValue 32-bit value used in compare operation.\r | |
200 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
201 | \r | |
202 | @return The original *Value before exchange.\r | |
203 | \r | |
204 | **/\r | |
205 | UINT32\r | |
206 | EFIAPI\r | |
207 | InterlockedCompareExchange32 (\r | |
208 | IN OUT UINT32 *Value,\r | |
209 | IN UINT32 CompareValue,\r | |
210 | IN UINT32 ExchangeValue\r | |
211 | );\r | |
212 | \r | |
213 | \r | |
214 | /**\r | |
215 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
216 | \r | |
217 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
218 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
219 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
220 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
221 | \r | |
222 | If Value is NULL, then ASSERT().\r | |
223 | \r | |
224 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
225 | operation.\r | |
226 | @param CompareValue 64-bit value used in compare operation.\r | |
227 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
228 | \r | |
229 | @return The original *Value before exchange.\r | |
230 | \r | |
231 | **/\r | |
232 | UINT64\r | |
233 | EFIAPI\r | |
234 | InterlockedCompareExchange64 (\r | |
235 | IN OUT UINT64 *Value,\r | |
236 | IN UINT64 CompareValue,\r | |
237 | IN UINT64 ExchangeValue\r | |
238 | );\r | |
239 | \r | |
240 | \r | |
241 | /**\r | |
242 | Performs an atomic compare exchange operation on a pointer value.\r | |
243 | \r | |
244 | Performs an atomic compare exchange operation on the pointer value specified\r | |
245 | by Value. If Value is equal to CompareValue, then Value is set to\r | |
246 | ExchangeValue and CompareValue is returned. If Value is not equal to\r | |
247 | CompareValue, then Value is returned. The compare exchange operation must be\r | |
248 | performed using MP safe mechanisms.\r | |
249 | \r | |
250 | If Value is NULL, then ASSERT().\r | |
251 | \r | |
252 | @param Value A pointer to the pointer value for the compare exchange\r | |
253 | operation.\r | |
254 | @param CompareValue Pointer value used in compare operation.\r | |
255 | @param ExchangeValue Pointer value used in exchange operation.\r | |
256 | \r | |
257 | @return The original *Value before exchange.\r | |
258 | **/\r | |
259 | VOID *\r | |
260 | EFIAPI\r | |
261 | InterlockedCompareExchangePointer (\r | |
262 | IN OUT VOID **Value,\r | |
263 | IN VOID *CompareValue,\r | |
264 | IN VOID *ExchangeValue\r | |
265 | );\r | |
266 | \r | |
267 | #endif\r | |
268 | \r | |
269 | \r |