]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/SynchronizationLib.h
2 Provides synchronization functions.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef __SYNCHRONIZATION_LIB__
10 #define __SYNCHRONIZATION_LIB__
13 /// Definitions for SPIN_LOCK
15 typedef volatile UINTN SPIN_LOCK
;
19 Retrieves the architecture-specific spin lock alignment requirements for
20 optimal spin lock performance.
22 This function retrieves the spin lock alignment requirements for optimal
23 performance on a given CPU architecture. The spin lock alignment is byte alignment.
24 It must be a power of two and is returned by this function. If there are no alignment
25 requirements, then 1 must be returned. The spin lock synchronization
26 functions must function correctly if the spin lock size and alignment values
27 returned by this function are not used at all. These values are hints to the
28 consumers of the spin lock synchronization functions to obtain optimal spin
31 @return The architecture-specific spin lock alignment.
36 GetSpinLockProperties (
42 Initializes a spin lock to the released state and returns the spin lock.
44 This function initializes the spin lock specified by SpinLock to the released
45 state, and returns SpinLock. Optimal performance can be achieved by calling
46 GetSpinLockProperties() to determine the size and alignment requirements for
49 If SpinLock is NULL, then ASSERT().
51 @param SpinLock A pointer to the spin lock to initialize to the released
54 @return SpinLock in release state.
60 OUT SPIN_LOCK
*SpinLock
65 Waits until a spin lock can be placed in the acquired state.
67 This function checks the state of the spin lock specified by SpinLock. If
68 SpinLock is in the released state, then this function places SpinLock in the
69 acquired state and returns SpinLock. Otherwise, this function waits
70 indefinitely for the spin lock to be released, and then places it in the
71 acquired state and returns SpinLock. All state transitions of SpinLock must
72 be performed using MP safe mechanisms.
74 If SpinLock is NULL, then ASSERT().
75 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
76 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
77 PcdSpinLockTimeout microseconds, then ASSERT().
79 @param SpinLock A pointer to the spin lock to place in the acquired state.
81 @return SpinLock acquired lock.
87 IN OUT SPIN_LOCK
*SpinLock
92 Attempts to place a spin lock in the acquired state.
94 This function checks the state of the spin lock specified by SpinLock. If
95 SpinLock is in the released state, then this function places SpinLock in the
96 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
97 transitions of SpinLock must be performed using MP safe mechanisms.
99 If SpinLock is NULL, then ASSERT().
100 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
102 @param SpinLock A pointer to the spin lock to place in the acquired state.
104 @retval TRUE SpinLock was placed in the acquired state.
105 @retval FALSE SpinLock could not be acquired.
110 AcquireSpinLockOrFail (
111 IN OUT SPIN_LOCK
*SpinLock
116 Releases a spin lock.
118 This function places the spin lock specified by SpinLock in the release state
119 and returns SpinLock.
121 If SpinLock is NULL, then ASSERT().
122 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
124 @param SpinLock A pointer to the spin lock to release.
126 @return SpinLock released lock.
132 IN OUT SPIN_LOCK
*SpinLock
137 Performs an atomic increment of a 32-bit unsigned integer.
139 Performs an atomic increment of the 32-bit unsigned integer specified by
140 Value and returns the incremented value. The increment operation must be
141 performed using MP safe mechanisms.
143 If Value is NULL, then ASSERT().
145 @param Value A pointer to the 32-bit value to increment.
147 @return The incremented value.
152 InterlockedIncrement (
153 IN
volatile UINT32
*Value
158 Performs an atomic decrement of a 32-bit unsigned integer.
160 Performs an atomic decrement of the 32-bit unsigned integer specified by
161 Value and returns the decremented value. The decrement operation must be
162 performed using MP safe mechanisms.
164 If Value is NULL, then ASSERT().
166 @param Value A pointer to the 32-bit value to decrement.
168 @return The decremented value.
173 InterlockedDecrement (
174 IN
volatile UINT32
*Value
179 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
181 Performs an atomic compare exchange operation on the 16-bit unsigned integer
182 specified by Value. If Value is equal to CompareValue, then Value is set to
183 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
184 then Value is returned. The compare exchange operation must be performed using
187 If Value is NULL, then ASSERT().
189 @param Value A pointer to the 16-bit value for the compare exchange
191 @param CompareValue 16-bit value used in compare operation.
192 @param ExchangeValue 16-bit value used in exchange operation.
194 @return The original *Value before exchange.
198 InterlockedCompareExchange16 (
199 IN OUT
volatile UINT16
*Value
,
200 IN UINT16 CompareValue
,
201 IN UINT16 ExchangeValue
205 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
207 Performs an atomic compare exchange operation on the 32-bit unsigned integer
208 specified by Value. If Value is equal to CompareValue, then Value is set to
209 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
210 then Value is returned. The compare exchange operation must be performed using
213 If Value is NULL, then ASSERT().
215 @param Value A pointer to the 32-bit value for the compare exchange
217 @param CompareValue 32-bit value used in compare operation.
218 @param ExchangeValue 32-bit value used in exchange operation.
220 @return The original *Value before exchange.
225 InterlockedCompareExchange32 (
226 IN OUT
volatile UINT32
*Value
,
227 IN UINT32 CompareValue
,
228 IN UINT32 ExchangeValue
233 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
235 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
236 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
237 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
238 The compare exchange operation must be performed using MP safe mechanisms.
240 If Value is NULL, then ASSERT().
242 @param Value A pointer to the 64-bit value for the compare exchange
244 @param CompareValue 64-bit value used in compare operation.
245 @param ExchangeValue 64-bit value used in exchange operation.
247 @return The original *Value before exchange.
252 InterlockedCompareExchange64 (
253 IN OUT
volatile UINT64
*Value
,
254 IN UINT64 CompareValue
,
255 IN UINT64 ExchangeValue
260 Performs an atomic compare exchange operation on a pointer value.
262 Performs an atomic compare exchange operation on the pointer value specified
263 by Value. If Value is equal to CompareValue, then Value is set to
264 ExchangeValue and CompareValue is returned. If Value is not equal to
265 CompareValue, then Value is returned. The compare exchange operation must be
266 performed using MP safe mechanisms.
268 If Value is NULL, then ASSERT().
270 @param Value A pointer to the pointer value for the compare exchange
272 @param CompareValue Pointer value used in compare operation.
273 @param ExchangeValue Pointer value used in exchange operation.
275 @return The original *Value before exchange.
279 InterlockedCompareExchangePointer (
280 IN OUT VOID
* volatile *Value
,
281 IN VOID
*CompareValue
,
282 IN VOID
*ExchangeValue