From a4ffdfff0d35e22368b3aec818888d9857052964 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sun, 30 Dec 2018 04:06:16 +0100 Subject: [PATCH] Separate ThreadPool...ThreadLocals get from initalization (dotnet/coreclr#21704) * Seperate ThreadPool...ThreadLocals get from initalization * Assert null Commit migrated from https://github.com/dotnet/coreclr/commit/ae04b48450680cc6988fc0ba4678b4c973180cd2 --- .../src/System/Threading/ThreadPool.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs index 2f77425..cc42b59 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs @@ -402,9 +402,16 @@ namespace System.Threading loggingEnabled = FrameworkEventSource.Log.IsEnabled(EventLevel.Verbose, FrameworkEventSource.Keywords.ThreadPool | FrameworkEventSource.Keywords.ThreadTransfer); } - public ThreadPoolWorkQueueThreadLocals EnsureCurrentThreadHasQueue() => - ThreadPoolWorkQueueThreadLocals.threadLocals ?? - (ThreadPoolWorkQueueThreadLocals.threadLocals = new ThreadPoolWorkQueueThreadLocals(this)); + public ThreadPoolWorkQueueThreadLocals GetOrCreateThreadLocals() => + ThreadPoolWorkQueueThreadLocals.threadLocals ?? CreateThreadLocals(); + + [MethodImpl(MethodImplOptions.NoInlining)] + private ThreadPoolWorkQueueThreadLocals CreateThreadLocals() + { + Debug.Assert(ThreadPoolWorkQueueThreadLocals.threadLocals == null); + + return (ThreadPoolWorkQueueThreadLocals.threadLocals = new ThreadPoolWorkQueueThreadLocals(this)); + } internal void EnsureThreadRequested() { @@ -545,7 +552,7 @@ namespace System.Threading // // Use operate on workQueue local to try block so it can be enregistered ThreadPoolWorkQueue workQueue = outerWorkQueue; - ThreadPoolWorkQueueThreadLocals tl = workQueue.EnsureCurrentThreadHasQueue(); + ThreadPoolWorkQueueThreadLocals tl = workQueue.GetOrCreateThreadLocals(); Thread currentThread = tl.currentThread; // Start on clean ExecutionContext and SynchronizationContext -- 2.7.4