X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseLib%2FSynchronization.c;h=59919a7f03b1ac1955d1075fd30585d060e10c94;hp=4c4734523d4a88f665499f8a6d634a61f8c3d37f;hb=eb9603a0b7c72b33c43bde89ec33d384cd30ce9e;hpb=0ffa12863e9e60cfd1900e3a83b21f32f89afdf2 diff --git a/MdePkg/Library/BaseLib/Synchronization.c b/MdePkg/Library/BaseLib/Synchronization.c index 4c4734523d..59919a7f03 100644 --- a/MdePkg/Library/BaseLib/Synchronization.c +++ b/MdePkg/Library/BaseLib/Synchronization.c @@ -14,36 +14,14 @@ **/ -#define SPIN_LOCK_RELEASED ((SPIN_LOCK)1) -#define SPIN_LOCK_ACQUIRED ((SPIN_LOCK)2) +#include "BaseLibInternals.h" -UINT32 -EFIAPI -InternalSyncIncrement ( - IN volatile UINT32 *Value - ); - -UINT32 -EFIAPI -InternalSyncDecrement ( - IN volatile UINT32 *Value - ); - -UINT32 -EFIAPI -InternalSyncCompareExchange32 ( - IN volatile UINT32 *Value, - IN UINT32 CompareValue, - IN UINT32 ExchangeValue - ); - -UINT64 -EFIAPI -InternalSyncCompareExchange64 ( - IN volatile UINT64 *Value, - IN UINT64 CompareValue, - IN UINT64 ExchangeValue - ); +// +// SPIN_LOCK_RELEASED & SPIN_LOCK_ACQUIRED should belong to type "SPIN_LOCK". +// Here we use type-case "UINTN" to avoid "volatile" modifier on const integers. +// +#define SPIN_LOCK_RELEASED ((UINTN) 1) +#define SPIN_LOCK_ACQUIRED ((UINTN) 2) /** Retrieves the architecture specific spin lock alignment requirements for @@ -131,12 +109,12 @@ AcquireSpinLock ( Tick = 0; Start = 0; End = 0; - if (FixedPcdGet32 (PcdSpinLockTimeout) > 0) { + if (PcdGet32 (PcdSpinLockTimeout) > 0) { Tick = GetPerformanceCounter (); Timeout = DivU64x32 ( MultU64x32 ( GetPerformanceCounterProperties (&Start, &End), - FixedPcdGet32 (PcdSpinLockTimeout) + PcdGet32 (PcdSpinLockTimeout) ), 1000000 ); @@ -177,8 +155,13 @@ AcquireSpinLockOrFail ( IN OUT SPIN_LOCK *SpinLock ) { + SPIN_LOCK LockValue; + ASSERT (SpinLock != NULL); - ASSERT (*SpinLock == SPIN_LOCK_ACQUIRED || *SpinLock == SPIN_LOCK_RELEASED); + + LockValue = *SpinLock; + ASSERT (LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED); + return (BOOLEAN)( InterlockedCompareExchangePointer ( (VOID**)SpinLock, @@ -208,8 +191,13 @@ ReleaseSpinLock ( IN OUT SPIN_LOCK *SpinLock ) { + SPIN_LOCK LockValue; + ASSERT (SpinLock != NULL); - ASSERT (*SpinLock == SPIN_LOCK_ACQUIRED || *SpinLock == SPIN_LOCK_RELEASED); + + LockValue = *SpinLock; + ASSERT (LockValue == SPIN_LOCK_ACQUIRED || LockValue == SPIN_LOCK_RELEASED); + *SpinLock = SPIN_LOCK_RELEASED; return SpinLock; } @@ -267,6 +255,14 @@ InterlockedDecrement ( /** Performs an atomic compare exchange operation on a 32-bit unsigned integer. + Performs an atomic compare exchange operation on the 32-bit unsigned integer + specified by Value. If Value is equal to CompareValue, then Value is set to + ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue, + then Value is returned. The compare exchange operation must be performed using + MP safe mechanisms. + + If Value is NULL, then ASSERT(). + @param Value A pointer to the 32-bit value for the compare exchange operation. @param CompareValue 32-bit value used in compare operation. @@ -290,6 +286,13 @@ InterlockedCompareExchange32 ( /** Performs an atomic compare exchange operation on a 64-bit unsigned integer. + Performs an atomic compare exchange operation on the 64-bit unsigned integer specified + by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and + CompareValue is returned. If Value is not equal to CompareValue, then Value is returned. + The compare exchange operation must be performed using MP safe mechanisms. + + If Value is NULL, then ASSERT(). + @param Value A pointer to the 64-bit value for the compare exchange operation. @param CompareValue 64-bit value used in compare operation. @@ -335,7 +338,11 @@ InterlockedCompareExchangePointer ( IN VOID *ExchangeValue ) { - switch (sizeof (*Value)) { + UINT8 SizeOfValue; + + SizeOfValue = sizeof (*Value); + + switch (SizeOfValue) { case sizeof (UINT32): return (VOID*)(UINTN)InterlockedCompareExchange32 ( (UINT32*)Value,