summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
diff options
context:
space:
mode:
authorJeff Fan <jeff.fan@intel.com>2016-03-21 13:26:46 +0800
committerHao Wu <hao.a.wu@intel.com>2016-07-15 09:10:48 +0800
commit0886aba0832570717e450f043af21182a8c46095 (patch)
tree996455b2d36d4b4d83f7cbcf2beec1f4a000ecec /MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
parent27f3000223b83c274168520981a051355e199b77 (diff)
downloadedk2-platforms-0886aba0832570717e450f043af21182a8c46095.tar.xz
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> (cherry picked from commit 0f18e1eda2a807283484adfbf5eaae6a92b1ffa7)
Diffstat (limited to 'MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c')
-rw-r--r--MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
index 587f5a771c..31f28ec2c5 100644
--- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
+++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c
@@ -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>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -114,7 +114,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 +162,6 @@ AcquireSpinLock (
Total += Delta;
ASSERT (Total < Timeout);
}
- } else {
- while (!AcquireSpinLockOrFail (SpinLock)) {
- CpuPause ();
- }
}
return SpinLock;
}