]>
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
;
18 Retrieves the architecture-specific spin lock alignment requirements for
19 optimal spin lock performance.
21 This function retrieves the spin lock alignment requirements for optimal
22 performance on a given CPU architecture. The spin lock alignment is byte alignment.
23 It must be a power of two and is returned by this function. If there are no alignment
24 requirements, then 1 must be returned. The spin lock synchronization
25 functions must function correctly if the spin lock size and alignment values
26 returned by this function are not used at all. These values are hints to the
27 consumers of the spin lock synchronization functions to obtain optimal spin
30 @return The architecture-specific spin lock alignment.
35 GetSpinLockProperties (
40 Initializes a spin lock to the released state and returns the spin lock.
42 This function initializes the spin lock specified by SpinLock to the released
43 state, and returns SpinLock. Optimal performance can be achieved by calling
44 GetSpinLockProperties() to determine the size and alignment requirements for
47 If SpinLock is NULL, then ASSERT().
49 @param SpinLock A pointer to the spin lock to initialize to the released
52 @return SpinLock in release state.
58 OUT SPIN_LOCK
*SpinLock
62 Waits until a spin lock can be placed in the acquired state.
64 This function checks the state of the spin lock specified by SpinLock. If
65 SpinLock is in the released state, then this function places SpinLock in the
66 acquired state and returns SpinLock. Otherwise, this function waits
67 indefinitely for the spin lock to be released, and then places it in the
68 acquired state and returns SpinLock. All state transitions of SpinLock must
69 be performed using MP safe mechanisms.
71 If SpinLock is NULL, then ASSERT().
72 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
73 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
74 PcdSpinLockTimeout microseconds, then ASSERT().
76 @param SpinLock A pointer to the spin lock to place in the acquired state.
78 @return SpinLock acquired lock.
84 IN OUT SPIN_LOCK
*SpinLock
88 Attempts to place a spin lock in the acquired state.
90 This function checks the state of the spin lock specified by SpinLock. If
91 SpinLock is in the released state, then this function places SpinLock in the
92 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
93 transitions of SpinLock must be performed using MP safe mechanisms.
95 If SpinLock is NULL, then ASSERT().
96 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
98 @param SpinLock A pointer to the spin lock to place in the acquired state.
100 @retval TRUE SpinLock was placed in the acquired state.
101 @retval FALSE SpinLock could not be acquired.
106 AcquireSpinLockOrFail (
107 IN OUT SPIN_LOCK
*SpinLock
111 Releases a spin lock.
113 This function places the spin lock specified by SpinLock in the release state
114 and returns SpinLock.
116 If SpinLock is NULL, then ASSERT().
117 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
119 @param SpinLock A pointer to the spin lock to release.
121 @return SpinLock released lock.
127 IN OUT SPIN_LOCK
*SpinLock
131 Performs an atomic increment of a 32-bit unsigned integer.
133 Performs an atomic increment of the 32-bit unsigned integer specified by
134 Value and returns the incremented value. The increment operation must be
135 performed using MP safe mechanisms.
137 If Value is NULL, then ASSERT().
139 @param Value A pointer to the 32-bit value to increment.
141 @return The incremented value.
146 InterlockedIncrement (
147 IN
volatile UINT32
*Value
151 Performs an atomic decrement of a 32-bit unsigned integer.
153 Performs an atomic decrement of the 32-bit unsigned integer specified by
154 Value and returns the decremented value. The decrement operation must be
155 performed using MP safe mechanisms.
157 If Value is NULL, then ASSERT().
159 @param Value A pointer to the 32-bit value to decrement.
161 @return The decremented value.
166 InterlockedDecrement (
167 IN
volatile UINT32
*Value
171 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
173 Performs an atomic compare exchange operation on the 16-bit unsigned integer
174 specified by Value. If Value is equal to CompareValue, then Value is set to
175 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
176 then Value is returned. The compare exchange operation must be performed using
179 If Value is NULL, then ASSERT().
181 @param Value A pointer to the 16-bit value for the compare exchange
183 @param CompareValue 16-bit value used in compare operation.
184 @param ExchangeValue 16-bit value used in exchange operation.
186 @return The original *Value before exchange.
190 InterlockedCompareExchange16 (
191 IN OUT
volatile UINT16
*Value
,
192 IN UINT16 CompareValue
,
193 IN UINT16 ExchangeValue
197 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
199 Performs an atomic compare exchange operation on the 32-bit unsigned integer
200 specified by Value. If Value is equal to CompareValue, then Value is set to
201 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
202 then Value is returned. The compare exchange operation must be performed using
205 If Value is NULL, then ASSERT().
207 @param Value A pointer to the 32-bit value for the compare exchange
209 @param CompareValue 32-bit value used in compare operation.
210 @param ExchangeValue 32-bit value used in exchange operation.
212 @return The original *Value before exchange.
217 InterlockedCompareExchange32 (
218 IN OUT
volatile UINT32
*Value
,
219 IN UINT32 CompareValue
,
220 IN UINT32 ExchangeValue
224 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
226 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
227 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
228 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
229 The compare exchange operation must be performed using MP safe mechanisms.
231 If Value is NULL, then ASSERT().
233 @param Value A pointer to the 64-bit value for the compare exchange
235 @param CompareValue 64-bit value used in compare operation.
236 @param ExchangeValue 64-bit value used in exchange operation.
238 @return The original *Value before exchange.
243 InterlockedCompareExchange64 (
244 IN OUT
volatile UINT64
*Value
,
245 IN UINT64 CompareValue
,
246 IN UINT64 ExchangeValue
250 Performs an atomic compare exchange operation on a pointer value.
252 Performs an atomic compare exchange operation on the pointer value specified
253 by Value. If Value is equal to CompareValue, then Value is set to
254 ExchangeValue and CompareValue is returned. If Value is not equal to
255 CompareValue, then Value is returned. The compare exchange operation must be
256 performed using MP safe mechanisms.
258 If Value is NULL, then ASSERT().
260 @param Value A pointer to the pointer value for the compare exchange
262 @param CompareValue Pointer value used in compare operation.
263 @param ExchangeValue Pointer value used in exchange operation.
265 @return The original *Value before exchange.
269 InterlockedCompareExchangePointer (
270 IN OUT VOID
*volatile *Value
,
271 IN VOID
*CompareValue
,
272 IN VOID
*ExchangeValue