Invert the dependency · dotnet/coreclr@cf79ed5 (original) (raw)
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree
2 files changed
lines changed
- src/System.Private.CoreLib
- shared/System/Runtime/CompilerServices
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,6 +3,7 @@ | ||
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 | |
5 | 5 | using System.Diagnostics; |
6 | +using System.Threading; | |
6 | 7 | using System.Threading.Tasks; |
7 | 8 | using System.Threading.Tasks.Sources; |
8 | 9 | |
@@ -101,25 +102,13 @@ void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox b | ||
101 | 102 | } |
102 | 103 | else if (obj != null) |
103 | 104 | { |
104 | -Unsafe.As<IValueTaskSource>(obj).OnCompleted(s_invokeAsyncStateMachineBox, box, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext); | |
105 | +Unsafe.As<IValueTaskSource>(obj).OnCompleted(ThreadPoolGlobals.s_invokeAsyncStateMachineBox, box, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext); | |
105 | 106 | } |
106 | 107 | else |
107 | 108 | { |
108 | 109 | TaskAwaiter.UnsafeOnCompletedInternal(Task.CompletedTask, box, continueOnCapturedContext: true); |
109 | 110 | } |
110 | 111 | } |
111 | - | |
112 | -/// |
|
113 | -internal static readonly Action<object> s_invokeAsyncStateMachineBox = state => | |
114 | -{ | |
115 | -if (!(state is IAsyncStateMachineBox box)) | |
116 | -{ | |
117 | -ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state); | |
118 | -return; | |
119 | -} | |
120 | - | |
121 | -box.MoveNext(); | |
122 | -}; | |
123 | 112 | #endif |
124 | 113 | } |
125 | 114 | |
@@ -201,7 +190,7 @@ void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox b | ||
201 | 190 | } |
202 | 191 | else if (obj != null) |
203 | 192 | { |
204 | -Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ValueTaskAwaiter.s_invokeAsyncStateMachineBox, box, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext); | |
193 | +Unsafe.As<IValueTaskSource<TResult>>(obj).OnCompleted(ThreadPoolGlobals.s_invokeAsyncStateMachineBox, box, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext); | |
205 | 194 | } |
206 | 195 | else |
207 | 196 | { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -37,6 +37,20 @@ internal static class ThreadPoolGlobals | ||
37 | 37 | public static bool enableWorkerTracking; |
38 | 38 | |
39 | 39 | public static readonly ThreadPoolWorkQueue workQueue = new ThreadPoolWorkQueue(); |
40 | + | |
41 | +#if CORECLR | |
42 | +/// |
|
43 | +internal static readonly Action<object> s_invokeAsyncStateMachineBox = state => | |
44 | +{ | |
45 | +if (!(state is IAsyncStateMachineBox box)) | |
46 | +{ | |
47 | +ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.state); | |
48 | +return; | |
49 | +} | |
50 | + | |
51 | +box.MoveNext(); | |
52 | +}; | |
53 | +#endif | |
40 | 54 | } |
41 | 55 | |
42 | 56 | [StructLayout(LayoutKind.Sequential)] // enforce layout so that padding reduces false sharing |
@@ -1316,7 +1330,7 @@ public static bool QueueUserWorkItem(Action callBack, TState sta | ||
1316 | 1330 | EnsureVMInitialized(); |
1317 | 1331 | |
1318 | 1332 | #if CORECLR |
1319 | -if (ReferenceEquals(callBack, ValueTaskAwaiter.s_invokeAsyncStateMachineBox)) | |
1333 | +if (ReferenceEquals(callBack, ThreadPoolGlobals.s_invokeAsyncStateMachineBox)) | |
1320 | 1334 | { |
1321 | 1335 | Debug.Assert(state is IAsyncStateMachineBox); |
1322 | 1336 |