summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Adams <thundercat@illyriad.co.uk>2019-06-06 01:36:16 +0100
committerJan Kotas <jkotas@microsoft.com>2019-06-05 17:36:16 -0700
commit8a569cfde41c0fdcf8c9013bdb30197c0fb19bd8 (patch)
tree0409e941fcd57c1ec1440427974d6e8880c024c3
parent8cb41af71ecff4e53fd02242b2710fcf6a4102ac (diff)
downloadcoreclr-8a569cfde41c0fdcf8c9013bdb30197c0fb19bd8.tar.gz
coreclr-8a569cfde41c0fdcf8c9013bdb30197c0fb19bd8.tar.bz2
coreclr-8a569cfde41c0fdcf8c9013bdb30197c0fb19bd8.zip
Less work for OptimalMaxSpinWaitsPerSpinIteration fast-path (#21702)
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
index 9b3118abba..f849358351 100644
--- a/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs
@@ -468,20 +468,22 @@ namespace System.Threading
{
get
{
- if (s_optimalMaxSpinWaitsPerSpinIteration != 0)
- {
- return s_optimalMaxSpinWaitsPerSpinIteration;
- }
-
- // This is done lazily because the first call to the function below in the process triggers a measurement that
- // takes a nontrivial amount of time if the measurement has not already been done in the backgorund.
- // See Thread::InitializeYieldProcessorNormalized(), which describes and calculates this value.
- s_optimalMaxSpinWaitsPerSpinIteration = GetOptimalMaxSpinWaitsPerSpinIterationInternal();
- Debug.Assert(s_optimalMaxSpinWaitsPerSpinIteration > 0);
- return s_optimalMaxSpinWaitsPerSpinIteration;
+ int optimalMaxSpinWaitsPerSpinIteration = s_optimalMaxSpinWaitsPerSpinIteration;
+ return optimalMaxSpinWaitsPerSpinIteration != 0 ? optimalMaxSpinWaitsPerSpinIteration : CalculateOptimalMaxSpinWaitsPerSpinIteration();
}
}
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static int CalculateOptimalMaxSpinWaitsPerSpinIteration()
+ {
+ // This is done lazily because the first call to the function below in the process triggers a measurement that
+ // takes a nontrivial amount of time if the measurement has not already been done in the backgorund.
+ // See Thread::InitializeYieldProcessorNormalized(), which describes and calculates this value.
+ s_optimalMaxSpinWaitsPerSpinIteration = GetOptimalMaxSpinWaitsPerSpinIterationInternal();
+ Debug.Assert(s_optimalMaxSpinWaitsPerSpinIteration > 0);
+ return s_optimalMaxSpinWaitsPerSpinIteration;
+ }
+
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int GetCurrentProcessorNumber();