]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/SynchronizationLib.h
ce3bce04f50acf66cb85c3665f1dbeeb2f9eece6
2 Provides synchronization functions.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __SYNCHRONIZATION_LIB__
16 #define __SYNCHRONIZATION_LIB__
19 /// Definitions for SPIN_LOCK
21 typedef volatile UINTN SPIN_LOCK
;
25 Retrieves the architecture-specific spin lock alignment requirements for
26 optimal spin lock performance.
28 This function retrieves the spin lock alignment requirements for optimal
29 performance on a given CPU architecture. The spin lock alignment is byte alignment.
30 It must be a power of two and is returned by this function. If there are no alignment
31 requirements, then 1 must be returned. The spin lock synchronization
32 functions must function correctly if the spin lock size and alignment values
33 returned by this function are not used at all. These values are hints to the
34 consumers of the spin lock synchronization functions to obtain optimal spin
37 @return The architecture-specific spin lock alignment.
42 GetSpinLockProperties (
48 Initializes a spin lock to the released state and returns the spin lock.
50 This function initializes the spin lock specified by SpinLock to the released
51 state, and returns SpinLock. Optimal performance can be achieved by calling
52 GetSpinLockProperties() to determine the size and alignment requirements for
55 If SpinLock is NULL, then ASSERT().
57 @param SpinLock A pointer to the spin lock to initialize to the released
60 @return SpinLock in release state.
66 OUT SPIN_LOCK
*SpinLock
71 Waits until a spin lock can be placed in the acquired state.
73 This function checks the state of the spin lock specified by SpinLock. If
74 SpinLock is in the released state, then this function places SpinLock in the
75 acquired state and returns SpinLock. Otherwise, this function waits
76 indefinitely for the spin lock to be released, and then places it in the
77 acquired state and returns SpinLock. All state transitions of SpinLock must
78 be performed using MP safe mechanisms.
80 If SpinLock is NULL, then ASSERT().
81 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
82 If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in
83 PcdSpinLockTimeout microseconds, then ASSERT().
85 @param SpinLock A pointer to the spin lock to place in the acquired state.
87 @return SpinLock acquired lock.
93 IN OUT SPIN_LOCK
*SpinLock
98 Attempts to place a spin lock in the acquired state.
100 This function checks the state of the spin lock specified by SpinLock. If
101 SpinLock is in the released state, then this function places SpinLock in the
102 acquired state and returns TRUE. Otherwise, FALSE is returned. All state
103 transitions of SpinLock must be performed using MP safe mechanisms.
105 If SpinLock is NULL, then ASSERT().
106 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
108 @param SpinLock A pointer to the spin lock to place in the acquired state.
110 @retval TRUE SpinLock was placed in the acquired state.
111 @retval FALSE SpinLock could not be acquired.
116 AcquireSpinLockOrFail (
117 IN OUT SPIN_LOCK
*SpinLock
122 Releases a spin lock.
124 This function places the spin lock specified by SpinLock in the release state
125 and returns SpinLock.
127 If SpinLock is NULL, then ASSERT().
128 If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().
130 @param SpinLock A pointer to the spin lock to release.
132 @return SpinLock released lock.
138 IN OUT SPIN_LOCK
*SpinLock
143 Performs an atomic increment of a 32-bit unsigned integer.
145 Performs an atomic increment of the 32-bit unsigned integer specified by
146 Value and returns the incremented value. The increment operation must be
147 performed using MP safe mechanisms.
149 If Value is NULL, then ASSERT().
151 @param Value A pointer to the 32-bit value to increment.
153 @return The incremented value.
158 InterlockedIncrement (
159 IN
volatile UINT32
*Value
164 Performs an atomic decrement of a 32-bit unsigned integer.
166 Performs an atomic decrement of the 32-bit unsigned integer specified by
167 Value and returns the decremented value. The decrement operation must be
168 performed using MP safe mechanisms.
170 If Value is NULL, then ASSERT().
172 @param Value A pointer to the 32-bit value to decrement.
174 @return The decremented value.
179 InterlockedDecrement (
180 IN
volatile UINT32
*Value
185 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
187 Performs an atomic compare exchange operation on the 16-bit unsigned integer
188 specified by Value. If Value is equal to CompareValue, then Value is set to
189 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
190 then Value is returned. The compare exchange operation must be performed using
193 If Value is NULL, then ASSERT().
195 @param Value A pointer to the 16-bit value for the compare exchange
197 @param CompareValue 16-bit value used in compare operation.
198 @param ExchangeValue 16-bit value used in exchange operation.
200 @return The original *Value before exchange.
204 InterlockedCompareExchange16 (
205 IN OUT
volatile UINT16
*Value
,
206 IN UINT16 CompareValue
,
207 IN UINT16 ExchangeValue
211 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
213 Performs an atomic compare exchange operation on the 32-bit unsigned integer
214 specified by Value. If Value is equal to CompareValue, then Value is set to
215 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
216 then Value is returned. The compare exchange operation must be performed using
219 If Value is NULL, then ASSERT().
221 @param Value A pointer to the 32-bit value for the compare exchange
223 @param CompareValue 32-bit value used in compare operation.
224 @param ExchangeValue 32-bit value used in exchange operation.
226 @return The original *Value before exchange.
231 InterlockedCompareExchange32 (
232 IN OUT
volatile UINT32
*Value
,
233 IN UINT32 CompareValue
,
234 IN UINT32 ExchangeValue
239 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
241 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
242 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
243 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
244 The compare exchange operation must be performed using MP safe mechanisms.
246 If Value is NULL, then ASSERT().
248 @param Value A pointer to the 64-bit value for the compare exchange
250 @param CompareValue 64-bit value used in compare operation.
251 @param ExchangeValue 64-bit value used in exchange operation.
253 @return The original *Value before exchange.
258 InterlockedCompareExchange64 (
259 IN OUT
volatile UINT64
*Value
,
260 IN UINT64 CompareValue
,
261 IN UINT64 ExchangeValue
266 Performs an atomic compare exchange operation on a pointer value.
268 Performs an atomic compare exchange operation on the pointer value specified
269 by Value. If Value is equal to CompareValue, then Value is set to
270 ExchangeValue and CompareValue is returned. If Value is not equal to
271 CompareValue, then Value is returned. The compare exchange operation must be
272 performed using MP safe mechanisms.
274 If Value is NULL, then ASSERT().
276 @param Value A pointer to the pointer value for the compare exchange
278 @param CompareValue Pointer value used in compare operation.
279 @param ExchangeValue Pointer value used in exchange operation.
281 @return The original *Value before exchange.
285 InterlockedCompareExchangePointer (
286 IN OUT VOID
* volatile *Value
,
287 IN VOID
*CompareValue
,
288 IN VOID
*ExchangeValue