MdePkg/BaseSynchronizationLib: Do not check timeout if lock released
Current AcquireSpinLock() will check if timeout happens when PcdSpinLockTimeout is not zero, even though the spin lock is already released. It may do unnecessary operation to read timer's counter. This update is trying to acquire spin lock firstly. If it could be acquired successfully, needn't to check timeout at all. Cc: Michael Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan <jeff.fan@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
Implementation of synchronization functions.
|
||||
|
||||
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||
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
|
||||
@ -104,7 +104,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
|
||||
//
|
||||
@ -148,10 +152,6 @@ AcquireSpinLock (
|
||||
Total += Delta;
|
||||
ASSERT (Total < Timeout);
|
||||
}
|
||||
} else {
|
||||
while (!AcquireSpinLockOrFail (SpinLock)) {
|
||||
CpuPause ();
|
||||
}
|
||||
}
|
||||
return SpinLock;
|
||||
}
|
||||
|
Reference in New Issue
Block a user