-\r
-//\r
-// Base Library Synchronization Functions\r
-//\r
-\r
-/**\r
- Retrieves the architecture specific spin lock alignment requirements for\r
- optimal spin lock performance.\r
-\r
- This function retrieves the spin lock alignment requirements for optimal\r
- performance on a given CPU architecture. The spin lock alignment must be a\r
- power of two and is returned by this function. If there are no alignment\r
- requirements, then 1 must be returned. The spin lock synchronization\r
- functions must function correctly if the spin lock size and alignment values\r
- returned by this function are not used at all. These values are hints to the\r
- consumers of the spin lock synchronization functions to obtain optimal spin\r
- lock performance.\r
-\r
- @return The architecture specific spin lock alignment.\r
-\r
-**/\r
-UINTN\r
-EFIAPI\r
-GetSpinLockProperties (\r
- VOID\r
- );\r
-\r
-\r
-/**\r
- Initializes a spin lock to the released state and returns the spin lock.\r
-\r
- This function initializes the spin lock specified by SpinLock to the released\r
- state, and returns SpinLock. Optimal performance can be achieved by calling\r
- GetSpinLockProperties() to determine the size and alignment requirements for\r
- SpinLock.\r
-\r
- If SpinLock is NULL, then ASSERT().\r
-\r
- @param SpinLock A pointer to the spin lock to initialize to the released\r
- state.\r
-\r
- @return SpinLock in release state.\r
-\r
-**/\r
-SPIN_LOCK *\r
-EFIAPI\r
-InitializeSpinLock (\r
- OUT SPIN_LOCK *SpinLock\r
- );\r
-\r
-\r
-/**\r
- Waits until a spin lock can be placed in the acquired state.\r
-\r
- This function checks the state of the spin lock specified by SpinLock. If\r
- SpinLock is in the released state, then this function places SpinLock in the\r
- acquired state and returns SpinLock. Otherwise, this function waits\r
- indefinitely for the spin lock to be released, and then places it in the\r
- acquired state and returns SpinLock. All state transitions of SpinLock must\r
- be performed using MP safe mechanisms.\r
-\r
- If SpinLock is NULL, then ASSERT().\r
- If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r
- If PcdSpinLockTimeout is not zero, and SpinLock is can not be acquired in\r
- PcdSpinLockTimeout microseconds, then ASSERT().\r
-\r
- @param SpinLock A pointer to the spin lock to place in the acquired state.\r
-\r
- @return SpinLock acquired lock.\r
-\r
-**/\r
-SPIN_LOCK *\r
-EFIAPI\r
-AcquireSpinLock (\r
- IN OUT SPIN_LOCK *SpinLock\r
- );\r
-\r
-\r
-/**\r
- Attempts to place a spin lock in the acquired state.\r
-\r
- This function checks the state of the spin lock specified by SpinLock. If\r
- SpinLock is in the released state, then this function places SpinLock in the\r
- acquired state and returns TRUE. Otherwise, FALSE is returned. All state\r
- transitions of SpinLock must be performed using MP safe mechanisms.\r
-\r
- If SpinLock is NULL, then ASSERT().\r
- If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r
-\r
- @param SpinLock A pointer to the spin lock to place in the acquired state.\r
-\r
- @retval TRUE SpinLock was placed in the acquired state.\r
- @retval FALSE SpinLock could not be acquired.\r
-\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-AcquireSpinLockOrFail (\r
- IN OUT SPIN_LOCK *SpinLock\r
- );\r
-\r
-\r
-/**\r
- Releases a spin lock.\r
-\r
- This function places the spin lock specified by SpinLock in the release state\r
- and returns SpinLock.\r
-\r
- If SpinLock is NULL, then ASSERT().\r
- If SpinLock was not initialized with InitializeSpinLock(), then ASSERT().\r
-\r
- @param SpinLock A pointer to the spin lock to release.\r
-\r
- @return SpinLock released lock.\r
-\r
-**/\r
-SPIN_LOCK *\r
-EFIAPI\r
-ReleaseSpinLock (\r
- IN OUT SPIN_LOCK *SpinLock\r
- );\r
-\r
-\r
-/**\r
- Performs an atomic increment of an 32-bit unsigned integer.\r
-\r
- Performs an atomic increment of the 32-bit unsigned integer specified by\r
- Value and returns the incremented value. The increment operation must be\r
- performed using MP safe mechanisms. The state of the return value is not\r
- guaranteed to be MP safe.\r
-\r
- If Value is NULL, then ASSERT().\r
-\r
- @param Value A pointer to the 32-bit value to increment.\r
-\r
- @return The incremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InterlockedIncrement (\r
- IN UINT32 *Value\r
- );\r
-\r
-\r
-/**\r
- Performs an atomic decrement of an 32-bit unsigned integer.\r
-\r
- Performs an atomic decrement of the 32-bit unsigned integer specified by\r
- Value and returns the decremented value. The decrement operation must be\r
- performed using MP safe mechanisms. The state of the return value is not\r
- guaranteed to be MP safe.\r
-\r
- If Value is NULL, then ASSERT().\r
-\r
- @param Value A pointer to the 32-bit value to decrement.\r
-\r
- @return The decremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InterlockedDecrement (\r
- IN UINT32 *Value\r
- );\r
-\r
-\r
-/**\r
- Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
-\r
- Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
- specified by Value. If Value is equal to CompareValue, then Value is set to\r
- ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
- then Value is returned. The compare exchange operation must be performed using\r
- MP safe mechanisms.\r
-\r
- If Value is NULL, then ASSERT().\r
-\r
- @param Value A pointer to the 32-bit value for the compare exchange\r
- operation.\r
- @param CompareValue 32-bit value used in compare operation.\r
- @param ExchangeValue 32-bit value used in exchange operation.\r
-\r
- @return The original *Value before exchange.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InterlockedCompareExchange32 (\r
- IN OUT UINT32 *Value,\r
- IN UINT32 CompareValue,\r
- IN UINT32 ExchangeValue\r
- );\r
-\r
-\r
-/**\r
- Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
-\r
- Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r
- by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
- CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r
- The compare exchange operation must be performed using MP safe mechanisms.\r
-\r
- If Value is NULL, then ASSERT().\r
-\r
- @param Value A pointer to the 64-bit value for the compare exchange\r
- operation.\r
- @param CompareValue 64-bit value used in compare operation.\r
- @param ExchangeValue 64-bit value used in exchange operation.\r
-\r
- @return The original *Value before exchange.\r
-\r
-**/\r
-UINT64\r
-EFIAPI\r
-InterlockedCompareExchange64 (\r
- IN OUT UINT64 *Value,\r
- IN UINT64 CompareValue,\r
- IN UINT64 ExchangeValue\r
- );\r
-\r
-\r
-/**\r
- Performs an atomic compare exchange operation on a pointer value.\r
-\r
- Performs an atomic compare exchange operation on the pointer value specified\r
- by Value. If Value is equal to CompareValue, then Value is set to\r
- ExchangeValue and CompareValue is returned. If Value is not equal to\r
- CompareValue, then Value is returned. The compare exchange operation must be\r
- performed using MP safe mechanisms.\r
-\r
- If Value is NULL, then ASSERT().\r
-\r
- @param Value A pointer to the pointer value for the compare exchange\r
- operation.\r
- @param CompareValue Pointer value used in compare operation.\r
- @param ExchangeValue Pointer value used in exchange operation.\r
-\r
- @return The original *Value before exchange.\r
-**/\r
-VOID *\r
-EFIAPI\r
-InterlockedCompareExchangePointer (\r
- IN OUT VOID **Value,\r
- IN VOID *CompareValue,\r
- IN VOID *ExchangeValue\r
- );\r
-\r
-\r