Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 672e93a

Browse files
committed
Reverse the polarity
1 parent b939185 commit 672e93a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/mscorlib/src/System/Threading/ThreadPool.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,17 +1208,17 @@ void IThreadPoolWorkItem.ExecuteWorkItem()
12081208
#if DEBUG
12091209
MarkExecuted(false);
12101210
#endif
1211-
if (context != null)
1212-
{
1213-
ExecutionContext.Run(context, ccb, this, true);
1214-
}
1215-
else
1211+
// call directly if it is an unsafe call OR EC flow is suppressed
1212+
if (context == null)
12161213
{
1217-
// call directly if it is an unsafe call OR EC flow is suppressed
12181214
WaitCallback cb = callback;
12191215
callback = null;
12201216
cb(state);
12211217
}
1218+
else
1219+
{
1220+
ExecutionContext.Run(context, ccb, this, true);
1221+
}
12221222
}
12231223

12241224
[SecurityCritical]
@@ -1679,19 +1679,10 @@ private static bool QueueUserWorkItemHelper(WaitCallback callBack, Object state,
16791679
ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase) :
16801680
null;
16811681

1682-
IThreadPoolWorkItem tpcallBack;
1683-
if (context == null)
1684-
{
1685-
tpcallBack = new QueueUserWorkItemCallback(callBack, state, null); // null context
1686-
}
1687-
else if (context.IsDefaultFTContext(true))
1688-
{
1689-
tpcallBack = new QueueUserWorkItemCallbackDefaultContext(callBack, state); // default context
1690-
}
1691-
else
1692-
{
1693-
tpcallBack = new QueueUserWorkItemCallback(callBack, state, context); // non-default context
1694-
}
1682+
IThreadPoolWorkItem tpcallBack = context == ExecutionContext.PreAllocatedDefault ?
1683+
new QueueUserWorkItemCallbackDefaultContext(callBack, state) :
1684+
(IThreadPoolWorkItem)new QueueUserWorkItemCallback(callBack, state, context);
1685+
16951686
ThreadPoolGlobals.workQueue.Enqueue(tpcallBack, true);
16961687
success = true;
16971688
}

0 commit comments

Comments
 (0)