diff options
author | Ben Adams <thundercat@illyriad.co.uk> | 2019-06-06 01:36:16 +0100 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-06-05 17:36:16 -0700 |
commit | 8a569cfde41c0fdcf8c9013bdb30197c0fb19bd8 (patch) | |
tree | 0409e941fcd57c1ec1440427974d6e8880c024c3 | |
parent | 8cb41af71ecff4e53fd02242b2710fcf6a4102ac (diff) | |
download | coreclr-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.cs | 24 |
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(); |