Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/MembersMustExist.AnalyzerData
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Visual Studio
private int System.Threading.Thread._managedThreadId
private int Internal.Runtime.Augments.RuntimeThread._managedThreadId

2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\TaskContinuation.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\TaskFactory.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Tasks\TPLETWProvider.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Thread.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\StackCrawlMark.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\ThreadPool.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Timer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Threading\Volatile.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using Internal.Runtime.Augments;

namespace System.Diagnostics
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,6 @@ private unsafe void CreateActivityPathGuid(out Guid idRet, out int activityPathG
activityPathGuidOffsetStart = m_creator.m_activityPathGuidOffset;
idRet = m_creator.m_guid;
}
else
{
// TODO FIXME - differentiate between AD inside PCL
int appDomainID = 0;
#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN)
appDomainID = System.Threading.Thread.GetDomainID();
#endif
// We start with the appdomain number to make this unique among appdomains.
activityPathGuidOffsetStart = AddIdToGuid(outPtr, activityPathGuidOffsetStart, (uint)appDomainID);
}

activityPathGuidOffset = AddIdToGuid(outPtr, activityPathGuidOffsetStart, (uint)m_uniqueId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using Internal.Runtime.Augments;
using Internal.Runtime.CompilerServices;
using Internal.Runtime.Augments;
using Internal.Threading.Tasks;
Expand Down Expand Up @@ -566,12 +567,12 @@ private class AsyncStateMachineBox<TStateMachine> : // SOS DumpAsync command dep
/// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
public Action MoveNextAction => _moveNextAction ?? (_moveNextAction = new Action(MoveNext));

internal sealed override void ExecuteFromThreadPool(Thread threadPoolThread) => MoveNext(threadPoolThread);
internal sealed override void ExecuteFromThreadPool(RuntimeThread threadPoolThread) => MoveNext(threadPoolThread);

/// <summary>Calls MoveNext on <see cref="StateMachine"/></summary>
public void MoveNext() => MoveNext(threadPoolThread: null);

private void MoveNext(Thread threadPoolThread)
private void MoveNext(RuntimeThread threadPoolThread)
{
Debug.Assert(!IsCompleted);

Expand Down Expand Up @@ -987,8 +988,8 @@ public static void Start<TStateMachine>(ref TStateMachine stateMachine) where TS

// enregistrer variables with 0 post-fix so they can be used in registers without EH forcing them to stack
// Capture references to Thread Contexts
Thread currentThread0 = Thread.CurrentThread;
Thread currentThread = currentThread0;
RuntimeThread currentThread0 = RuntimeThread.CurrentThread;
RuntimeThread currentThread = currentThread0;
ExecutionContext previousExecutionCtx0 = currentThread0.ExecutionContext;

// Store current ExecutionContext and SynchronizationContext as "previousXxx".
Expand All @@ -1005,7 +1006,7 @@ public static void Start<TStateMachine>(ref TStateMachine stateMachine) where TS
{
// Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
SynchronizationContext previousSyncCtx1 = previousSyncCtx;
Thread currentThread1 = currentThread;
RuntimeThread currentThread1 = currentThread;
// The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
if (previousSyncCtx1 != currentThread1.SynchronizationContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.Serialization;

using Thread = Internal.Runtime.Augments.RuntimeThread;
using Internal.Runtime.Augments;

namespace System.Threading
{
Expand Down Expand Up @@ -56,7 +55,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)

public static ExecutionContext Capture()
{
ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext;
ExecutionContext executionContext = RuntimeThread.CurrentThread.ExecutionContext;
if (executionContext == null)
{
executionContext = Default;
Expand Down Expand Up @@ -85,7 +84,7 @@ private ExecutionContext ShallowClone(bool isFlowSuppressed)

public static AsyncFlowControl SuppressFlow()
{
Thread currentThread = Thread.CurrentThread;
RuntimeThread currentThread = RuntimeThread.CurrentThread;
ExecutionContext executionContext = currentThread.ExecutionContext ?? Default;
if (executionContext.m_isFlowSuppressed)
{
Expand All @@ -101,7 +100,7 @@ public static AsyncFlowControl SuppressFlow()

public static void RestoreFlow()
{
Thread currentThread = Thread.CurrentThread;
RuntimeThread currentThread = RuntimeThread.CurrentThread;
ExecutionContext executionContext = currentThread.ExecutionContext;
if (executionContext == null || !executionContext.m_isFlowSuppressed)
{
Expand All @@ -113,7 +112,7 @@ public static void RestoreFlow()

public static bool IsFlowSuppressed()
{
ExecutionContext executionContext = Thread.CurrentThread.ExecutionContext;
ExecutionContext executionContext = RuntimeThread.CurrentThread.ExecutionContext;
return executionContext != null && executionContext.m_isFlowSuppressed;
}

Expand All @@ -140,8 +139,8 @@ internal static void RunInternal(ExecutionContext executionContext, ContextCallb

// Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack
// Capture references to Thread Contexts
Thread currentThread0 = Thread.CurrentThread;
Thread currentThread = currentThread0;
RuntimeThread currentThread0 = RuntimeThread.CurrentThread;
RuntimeThread currentThread = currentThread0;
ExecutionContext previousExecutionCtx0 = currentThread0.ExecutionContext;
if (previousExecutionCtx0 != null && previousExecutionCtx0.m_isDefault)
{
Expand Down Expand Up @@ -182,7 +181,7 @@ internal static void RunInternal(ExecutionContext executionContext, ContextCallb

// Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
SynchronizationContext previousSyncCtx1 = previousSyncCtx;
Thread currentThread1 = currentThread;
RuntimeThread currentThread1 = currentThread;
// The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
if (currentThread1.SynchronizationContext != previousSyncCtx1)
{
Expand Down Expand Up @@ -210,8 +209,8 @@ internal static void RunInternal<TState>(ExecutionContext executionContext, Cont

// Enregister variables with 0 post-fix so they can be used in registers without EH forcing them to stack
// Capture references to Thread Contexts
Thread currentThread0 = Thread.CurrentThread;
Thread currentThread = currentThread0;
RuntimeThread currentThread0 = RuntimeThread.CurrentThread;
RuntimeThread currentThread = currentThread0;
ExecutionContext previousExecutionCtx0 = currentThread0.ExecutionContext;
if (previousExecutionCtx0 != null && previousExecutionCtx0.m_isDefault)
{
Expand Down Expand Up @@ -252,7 +251,7 @@ internal static void RunInternal<TState>(ExecutionContext executionContext, Cont

// Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack
SynchronizationContext previousSyncCtx1 = previousSyncCtx;
Thread currentThread1 = currentThread;
RuntimeThread currentThread1 = currentThread;
// The common case is that these have not changed, so avoid the cost of a write barrier if not needed.
if (currentThread1.SynchronizationContext != previousSyncCtx1)
{
Expand All @@ -271,9 +270,9 @@ internal static void RunInternal<TState>(ExecutionContext executionContext, Cont
edi?.Throw();
}

internal static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)
internal static void RunFromThreadPoolDispatchLoop(RuntimeThread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)
{
Debug.Assert(threadPoolThread == Thread.CurrentThread);
Debug.Assert(threadPoolThread == RuntimeThread.CurrentThread);
CheckThreadPoolAndContextsAreDefault();
// ThreadPool starts on Default Context so we don't need to save the "previous" state as we know it is Default (null)

Expand All @@ -298,7 +297,7 @@ internal static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, Exec
}

// Enregister threadPoolThread as it crossed EH, and use enregistered variable
Thread currentThread = threadPoolThread;
RuntimeThread currentThread = threadPoolThread;

ExecutionContext currentExecutionCtx = currentThread.ExecutionContext;

Expand All @@ -324,7 +323,7 @@ internal static void RunForThreadPoolUnsafe<TState>(ExecutionContext executionCo
Debug.Assert(executionContext != null && !executionContext.m_isDefault, "ExecutionContext argument is Default.");

// Restore Non-Default context
Thread.CurrentThread.ExecutionContext = executionContext;
RuntimeThread.CurrentThread.ExecutionContext = executionContext;
if (executionContext.HasChangeNotifications)
{
OnValuesChanged(previousExecutionCtx: null, executionContext);
Expand All @@ -335,9 +334,9 @@ internal static void RunForThreadPoolUnsafe<TState>(ExecutionContext executionCo
// ThreadPoolWorkQueue.Dispatch will handle notifications and reset EC and SyncCtx back to default
}

internal static void RestoreChangedContextToThread(Thread currentThread, ExecutionContext contextToRestore, ExecutionContext currentContext)
internal static void RestoreChangedContextToThread(RuntimeThread currentThread, ExecutionContext contextToRestore, ExecutionContext currentContext)
{
Debug.Assert(currentThread == Thread.CurrentThread);
Debug.Assert(currentThread == RuntimeThread.CurrentThread);
Debug.Assert(contextToRestore != currentContext);

// Restore changed ExecutionContext back to previous
Expand All @@ -352,7 +351,7 @@ internal static void RestoreChangedContextToThread(Thread currentThread, Executi

// Inline as only called in one place and always called
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void ResetThreadPoolThread(Thread currentThread)
internal static void ResetThreadPoolThread(RuntimeThread currentThread)
{
ExecutionContext currentExecutionCtx = currentThread.ExecutionContext;

Expand All @@ -373,9 +372,9 @@ internal static void ResetThreadPoolThread(Thread currentThread)
[System.Diagnostics.Conditional("DEBUG")]
internal static void CheckThreadPoolAndContextsAreDefault()
{
Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
Debug.Assert(Thread.CurrentThread.ExecutionContext == null, "ThreadPool thread not on Default ExecutionContext.");
Debug.Assert(Thread.CurrentThread.SynchronizationContext == null, "ThreadPool thread not on Default SynchronizationContext.");
Debug.Assert(RuntimeThread.CurrentThread.IsThreadPoolThread);
Debug.Assert(RuntimeThread.CurrentThread.ExecutionContext == null, "ThreadPool thread not on Default ExecutionContext.");
Debug.Assert(RuntimeThread.CurrentThread.SynchronizationContext == null, "ThreadPool thread not on Default SynchronizationContext.");
}

internal static void OnValuesChanged(ExecutionContext previousExecutionCtx, ExecutionContext nextExecutionCtx)
Expand Down Expand Up @@ -472,7 +471,7 @@ private static void ThrowNullContext()

internal static object GetLocalValue(IAsyncLocal local)
{
ExecutionContext current = Thread.CurrentThread.ExecutionContext;
ExecutionContext current = RuntimeThread.CurrentThread.ExecutionContext;
if (current == null)
{
return null;
Expand All @@ -484,7 +483,7 @@ internal static object GetLocalValue(IAsyncLocal local)

internal static void SetLocalValue(IAsyncLocal local, object newValue, bool needChangeNotifications)
{
ExecutionContext current = Thread.CurrentThread.ExecutionContext;
ExecutionContext current = RuntimeThread.CurrentThread.ExecutionContext;

object previousValue = null;
bool hadPreviousValue = false;
Expand Down Expand Up @@ -542,7 +541,7 @@ internal static void SetLocalValue(IAsyncLocal local, object newValue, bool need
}
}

Thread.CurrentThread.ExecutionContext =
RuntimeThread.CurrentThread.ExecutionContext =
(!isFlowSuppressed && AsyncLocalValueMap.IsEmpty(newValues)) ?
null : // No values, return to Default context
new ExecutionContext(newValues, newChangeNotifications, isFlowSuppressed);
Expand All @@ -566,11 +565,11 @@ public void Dispose()

public struct AsyncFlowControl : IDisposable
{
private Thread _thread;
private RuntimeThread _thread;

internal void Initialize(Thread currentThread)
internal void Initialize(RuntimeThread currentThread)
{
Debug.Assert(currentThread == Thread.CurrentThread);
Debug.Assert(currentThread == RuntimeThread.CurrentThread);
_thread = currentThread;
}

Expand All @@ -580,7 +579,7 @@ public void Undo()
{
throw new InvalidOperationException(SR.InvalidOperation_CannotUseAFCMultiple);
}
if (Thread.CurrentThread != _thread)
if (RuntimeThread.CurrentThread != _thread)
{
throw new InvalidOperationException(SR.InvalidOperation_CannotUseAFCOtherThread);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

using System.Diagnostics;
using System.Threading.Tasks;

using Thread = Internal.Runtime.Augments.RuntimeThread;
using Internal.Runtime.Augments;

namespace System.Threading
{
Expand Down Expand Up @@ -78,7 +77,7 @@ private sealed class TaskNode : Task<bool>
internal TaskNode Prev, Next;
internal TaskNode() : base() { }

internal override void ExecuteFromThreadPool(Thread threadPoolThread)
internal override void ExecuteFromThreadPool(RuntimeThread threadPoolThread)
{
bool setSuccessfully = TrySetResult(true);
Debug.Assert(setSuccessfully, "Should have been able to complete task");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace System.Threading
/// In most cases, you should use the synchronization classes provided by the .NET Framework, such as
/// <see cref="System.Threading.Monitor"/>. For most purposes where spin waiting is required, however,
/// the <see cref="SpinWait"/> type should be preferred over the <see
/// cref="System.Threading.Thread.SpinWait"/> method.
/// cref="System.Threading.RuntimeThread.SpinWait"/> method.
/// </para>
/// <para>
/// While SpinWait is designed to be used in concurrent applications, it is not designed to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

using Thread = Internal.Runtime.Augments.RuntimeThread;
using Internal.Runtime.Augments;

namespace System.Threading.Tasks
{
Expand Down Expand Up @@ -603,7 +602,7 @@ protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQu
// since it'll only allow inlining if it can find the task in the local queue).
// As such, if we're not on a thread pool thread, we know for sure the
// task won't be inlined, so let's not even try.
if (isDefaultScheduler && taskWasPreviouslyQueued && !Thread.CurrentThread.IsThreadPoolThread)
if (isDefaultScheduler && taskWasPreviouslyQueued && !RuntimeThread.CurrentThread.IsThreadPoolThread)
{
return false;
}
Expand Down
Loading