Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Mirror changes from dotnet/coreclr,corefx #6805

Merged
merged 3 commits into from Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,6 +54,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\IPinnable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\MemoryHandle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\MemoryManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\OperationStatus.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\StandardFormat.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\TlsOverPerCoreLockedStacksArrayPool.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\Utilities.cs" />
Expand Down Expand Up @@ -205,6 +206,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\DuplicateWaitObjectException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Empty.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\EntryPointNotFoundException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\EnvironmentVariableTarget.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\EventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\EventHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ExecutionEngineException.cs" />
Expand Down
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Buffers
{
/// <summary>
/// This enum defines the various potential status that can be returned from Span-based operations
/// that support processing of input contained in multiple discontiguous buffers.
/// </summary>
public enum OperationStatus
{
/// <summary>
/// The entire input buffer has been processed and the operation is complete.
/// </summary>
Done,
/// <summary>
/// The input is partially processed, up to what could fit into the destination buffer.
/// The caller can enlarge the destination buffer, slice the buffers appropriately, and retry.
/// </summary>
DestinationTooSmall,
/// <summary>
/// The input is partially processed, up to the last valid chunk of the input that could be consumed.
/// The caller can stitch the remaining unprocessed input with more data, slice the buffers appropriately, and retry.
/// </summary>
NeedMoreData,
/// <summary>
/// The input contained invalid bytes which could not be processed. If the input is partially processed,
/// the destination contains the partial result. This guarantees that no additional data appended to the input
/// will make the invalid sequence valid.
/// </summary>
InvalidData,
}
}
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System
{
public enum EnvironmentVariableTarget
{
Process = 0,
User = 1,
Machine = 2,
}
}
Expand Up @@ -164,14 +164,7 @@ internal static void RunInternal(ExecutionContext executionContext, ContextCallb

if (previousExecutionCtx0 != executionContext)
{
// Restore changed ExecutionContext
currentThread0.ExecutionContext = executionContext;
if ((executionContext != null && executionContext.HasChangeNotifications) ||
(previousExecutionCtx0 != null && previousExecutionCtx0.HasChangeNotifications))
{
// There are change notifications; trigger any affected
OnValuesChanged(previousExecutionCtx0, executionContext);
}
RestoreChangedContextToThread(currentThread0, executionContext, previousExecutionCtx0);
}

ExceptionDispatchInfo edi = null;
Expand Down Expand Up @@ -201,14 +194,7 @@ internal static void RunInternal(ExecutionContext executionContext, ContextCallb
ExecutionContext currentExecutionCtx1 = currentThread1.ExecutionContext;
if (currentExecutionCtx1 != previousExecutionCtx1)
{
// Restore changed ExecutionContext back to previous
currentThread1.ExecutionContext = previousExecutionCtx1;
if ((currentExecutionCtx1 != null && currentExecutionCtx1.HasChangeNotifications) ||
(previousExecutionCtx1 != null && previousExecutionCtx1.HasChangeNotifications))
{
// There are change notifications; trigger any affected
OnValuesChanged(currentExecutionCtx1, previousExecutionCtx1);
}
RestoreChangedContextToThread(currentThread1, previousExecutionCtx1, currentExecutionCtx1);
}

// If exception was thrown by callback, rethrow it now original contexts are restored
Expand Down Expand Up @@ -248,14 +234,7 @@ internal static void RunInternal<TState>(ExecutionContext executionContext, Cont

if (previousExecutionCtx0 != executionContext)
{
// Restore changed ExecutionContext
currentThread0.ExecutionContext = executionContext;
if ((executionContext != null && executionContext.HasChangeNotifications) ||
(previousExecutionCtx0 != null && previousExecutionCtx0.HasChangeNotifications))
{
// There are change notifications; trigger any affected
OnValuesChanged(previousExecutionCtx0, executionContext);
}
RestoreChangedContextToThread(currentThread0, executionContext, previousExecutionCtx0);
}

ExceptionDispatchInfo edi = null;
Expand Down Expand Up @@ -285,14 +264,7 @@ internal static void RunInternal<TState>(ExecutionContext executionContext, Cont
ExecutionContext currentExecutionCtx1 = currentThread1.ExecutionContext;
if (currentExecutionCtx1 != previousExecutionCtx1)
{
// Restore changed ExecutionContext back to previous
currentThread1.ExecutionContext = previousExecutionCtx1;
if ((currentExecutionCtx1 != null && currentExecutionCtx1.HasChangeNotifications) ||
(previousExecutionCtx1 != null && previousExecutionCtx1.HasChangeNotifications))
{
// There are change notifications; trigger any affected
OnValuesChanged(currentExecutionCtx1, previousExecutionCtx1);
}
RestoreChangedContextToThread(currentThread1, previousExecutionCtx1, currentExecutionCtx1);
}

// If exception was thrown by callback, rethrow it now original contexts are restored
Expand All @@ -305,20 +277,11 @@ internal static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, Exec
CheckThreadPoolAndContextsAreDefault();
// ThreadPool starts on Default Context so we don't need to save the "previous" state as we know it is Default (null)

if (executionContext != null && executionContext.m_isDefault)
{
// Default is a null ExecutionContext internally
executionContext = null;
}
else if (executionContext != null)
// Default is a null ExecutionContext internally
if (executionContext != null && !executionContext.m_isDefault)
{
// Non-Default context to restore
threadPoolThread.ExecutionContext = executionContext;
if (executionContext.HasChangeNotifications)
{
// There are change notifications; trigger any affected
OnValuesChanged(previousExecutionCtx: null, executionContext);
}
RestoreChangedContextToThread(threadPoolThread, contextToRestore: executionContext, currentContext: null);
}

ExceptionDispatchInfo edi = null;
Expand All @@ -345,14 +308,7 @@ internal static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, Exec
{
// The EC always needs to be reset for this overload, as it will flow back to the caller if it performs
// extra work prior to returning to the Dispatch loop. For example for Task-likes it will flow out of await points

// Restore to Default before Notifications, as the change can be observed in the handler.
currentThread.ExecutionContext = null;
if (currentExecutionCtx.HasChangeNotifications)
{
// There are change notifications; trigger any affected
OnValuesChanged(currentExecutionCtx, nextExecutionCtx: null);
}
RestoreChangedContextToThread(currentThread, contextToRestore: null, currentExecutionCtx);
}

// If exception was thrown by callback, rethrow it now original contexts are restored
Expand All @@ -367,9 +323,8 @@ internal static void RunForThreadPoolUnsafe<TState>(ExecutionContext executionCo
CheckThreadPoolAndContextsAreDefault();
Debug.Assert(executionContext != null && !executionContext.m_isDefault, "ExecutionContext argument is Default.");

Thread currentThread = Thread.CurrentThread;
// Restore Non-Default context
currentThread.ExecutionContext = executionContext;
Thread.CurrentThread.ExecutionContext = executionContext;
if (executionContext.HasChangeNotifications)
{
OnValuesChanged(previousExecutionCtx: null, executionContext);
Expand All @@ -380,6 +335,21 @@ 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)
{
Debug.Assert(currentThread == Thread.CurrentThread);
Debug.Assert(contextToRestore != currentContext);

// Restore changed ExecutionContext back to previous
currentThread.ExecutionContext = contextToRestore;
if ((currentContext != null && currentContext.HasChangeNotifications) ||
(contextToRestore != null && contextToRestore.HasChangeNotifications))
{
// There are change notifications; trigger any affected
OnValuesChanged(currentContext, contextToRestore);
}
}

// Inline as only called in one place and always called
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void ResetThreadPoolThread(Thread currentThread)
Expand Down
7 changes: 0 additions & 7 deletions src/System.Private.CoreLib/src/System/Environment.cs
Expand Up @@ -22,13 +22,6 @@

namespace System
{
public enum EnvironmentVariableTarget
{
Process = 0,
User = 1,
Machine = 2,
}

internal static partial class Environment
{
/*==================================TickCount===================================
Expand Down