X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseSynchronizationLib%2FSynchronizationGcc.c;h=466775e6021ee701ed7cf267848d4aab9790cd57;hb=9344f0921518309295da89c221d10cbead8531aa;hp=ea28ce0dafba6f7d499d3dd5a285b3832d26defc;hpb=acbcf0425f4fa835d3455df86c6e505b5095cd51;p=mirror_edk2.git diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c index ea28ce0daf..466775e602 100644 --- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c +++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c @@ -1,22 +1,16 @@ /** @file Implementation of synchronization functions. - Copyright (c) 2006 - 2008, Intel Corporation
- Portions copyright (c) 2008-2009 Apple Inc. All rights reserved.
- All rights reserved. This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "BaseSynchronizationLibInternals.h" // -// GCC inline assembly for Read Write Barrier +// GCC inline assembly for Read Write Barrier // #define _ReadWriteBarrier() do { __asm__ __volatile__ ("": : : "memory"); } while(0) @@ -28,8 +22,8 @@ optimal spin lock performance. This function retrieves the spin lock alignment requirements for optimal - performance on a given CPU architecture. The spin lock alignment must be a - power of two and is returned by this function. If there are no alignment + performance on a given CPU architecture. The spin lock alignment is byte alignment. + It must be a power of two and is returned by this function. If there are no alignment requirements, then 1 must be returned. The spin lock synchronization functions must function correctly if the spin lock size and alignment values returned by this function are not used at all. These values are hints to the @@ -45,7 +39,7 @@ GetSpinLockProperties ( VOID ) { - return 32; + return InternalGetSpinLockProperties (); } /** @@ -61,7 +55,7 @@ GetSpinLockProperties ( @param SpinLock A pointer to the spin lock to initialize to the released state. - @return SpinLock in release state. + @return SpinLock is in release state. **/ SPIN_LOCK * @@ -96,7 +90,7 @@ InitializeSpinLock ( @param SpinLock A pointer to the spin lock to place in the acquired state. - @return SpinLock acquired lock. + @return SpinLock acquired the lock. **/ SPIN_LOCK * @@ -114,7 +108,11 @@ AcquireSpinLock ( INT64 Cycle; INT64 Delta; - if (PcdGet32 (PcdSpinLockTimeout) > 0) { + if (PcdGet32 (PcdSpinLockTimeout) == 0) { + while (!AcquireSpinLockOrFail (SpinLock)) { + CpuPause (); + } + } else if (!AcquireSpinLockOrFail (SpinLock)) { // // Get the current timer value // @@ -158,10 +156,6 @@ AcquireSpinLock ( Total += Delta; ASSERT (Total < Timeout); } - } else { - while (!AcquireSpinLockOrFail (SpinLock)) { - CpuPause (); - } } return SpinLock; } @@ -191,7 +185,7 @@ AcquireSpinLockOrFail ( { SPIN_LOCK LockValue; VOID *Result; - + ASSERT (SpinLock != NULL); LockValue = *SpinLock; @@ -219,7 +213,7 @@ AcquireSpinLockOrFail ( @param SpinLock A pointer to the spin lock to release. - @return SpinLock released lock. + @return SpinLock released the lock. **/ SPIN_LOCK * @@ -247,8 +241,7 @@ ReleaseSpinLock ( Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). @@ -260,7 +253,7 @@ ReleaseSpinLock ( UINT32 EFIAPI InterlockedIncrement ( - IN UINT32 *Value + IN volatile UINT32 *Value ) { ASSERT (Value != NULL); @@ -272,8 +265,7 @@ InterlockedIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). @@ -285,13 +277,44 @@ InterlockedIncrement ( UINT32 EFIAPI InterlockedDecrement ( - IN UINT32 *Value + IN volatile UINT32 *Value ) { ASSERT (Value != NULL); return InternalSyncDecrement (Value); } +/** + Performs an atomic compare exchange operation on a 16-bit unsigned integer. + + Performs an atomic compare exchange operation on the 16-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 16-bit value for the compare exchange + operation. + @param CompareValue A 16-bit value used in compare operation. + @param ExchangeValue A 16-bit value used in exchange operation. + + @return The original *Value before exchange. + +**/ +UINT16 +EFIAPI +InterlockedCompareExchange16 ( + IN OUT volatile UINT16 *Value, + IN UINT16 CompareValue, + IN UINT16 ExchangeValue + ) +{ + ASSERT (Value != NULL); + return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue); +} + /** Performs an atomic compare exchange operation on a 32-bit unsigned integer. @@ -305,8 +328,8 @@ InterlockedDecrement ( @param Value A pointer to the 32-bit value for the compare exchange operation. - @param CompareValue 32-bit value used in compare operation. - @param ExchangeValue 32-bit value used in exchange operation. + @param CompareValue A 32-bit value used in compare operation. + @param ExchangeValue A 32-bit value used in exchange operation. @return The original *Value before exchange. @@ -314,7 +337,7 @@ InterlockedDecrement ( UINT32 EFIAPI InterlockedCompareExchange32 ( - IN OUT UINT32 *Value, + IN OUT volatile UINT32 *Value, IN UINT32 CompareValue, IN UINT32 ExchangeValue ) @@ -335,8 +358,8 @@ InterlockedCompareExchange32 ( @param Value A pointer to the 64-bit value for the compare exchange operation. - @param CompareValue 64-bit value used in compare operation. - @param ExchangeValue 64-bit value used in exchange operation. + @param CompareValue A 64-bit value used in a compare operation. + @param ExchangeValue A 64-bit value used in an exchange operation. @return The original *Value before exchange. @@ -344,7 +367,7 @@ InterlockedCompareExchange32 ( UINT64 EFIAPI InterlockedCompareExchange64 ( - IN OUT UINT64 *Value, + IN OUT volatile UINT64 *Value, IN UINT64 CompareValue, IN UINT64 ExchangeValue ) @@ -366,15 +389,15 @@ InterlockedCompareExchange64 ( @param Value A pointer to the pointer value for the compare exchange operation. - @param CompareValue Pointer value used in compare operation. - @param ExchangeValue Pointer value used in exchange operation. + @param CompareValue A pointer value used in a compare operation. + @param ExchangeValue A pointer value used in an exchange operation. @return The original *Value before exchange. **/ VOID * EFIAPI InterlockedCompareExchangePointer ( - IN OUT VOID **Value, + IN OUT VOID * volatile *Value, IN VOID *CompareValue, IN VOID *ExchangeValue ) @@ -386,13 +409,13 @@ InterlockedCompareExchangePointer ( switch (SizeOfValue) { case sizeof (UINT32): return (VOID*)(UINTN)InterlockedCompareExchange32 ( - (UINT32*)Value, + (volatile UINT32 *)Value, (UINT32)(UINTN)CompareValue, (UINT32)(UINTN)ExchangeValue ); case sizeof (UINT64): return (VOID*)(UINTN)InterlockedCompareExchange64 ( - (UINT64*)Value, + (volatile UINT64 *)Value, (UINT64)(UINTN)CompareValue, (UINT64)(UINTN)ExchangeValue );