You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
|
||||
namespace System.Runtime
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
|
||||
public sealed class AssemblyTargetedPatchBandAttribute : Attribute
|
||||
{
|
||||
private String m_targetedPatchBand;
|
||||
|
||||
public AssemblyTargetedPatchBandAttribute(String targetedPatchBand)
|
||||
{
|
||||
m_targetedPatchBand = targetedPatchBand;
|
||||
}
|
||||
|
||||
public String TargetedPatchBand
|
||||
{
|
||||
get { return m_targetedPatchBand; }
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================================================
|
||||
// Sacrifices cheap servicing of a method body in order to allow unrestricted inlining. Certain types of
|
||||
// trivial methods (e.g. simple property getters) are automatically attributed by ILCA.EXE during the build.
|
||||
// For other performance critical methods, it should be added manually.
|
||||
//============================================================================================================
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
|
||||
public sealed class TargetedPatchingOptOutAttribute : Attribute
|
||||
{
|
||||
private String m_reason;
|
||||
|
||||
public TargetedPatchingOptOutAttribute(String reason)
|
||||
{
|
||||
m_reason = reason;
|
||||
}
|
||||
|
||||
public String Reason
|
||||
{
|
||||
get { return m_reason; }
|
||||
}
|
||||
|
||||
private TargetedPatchingOptOutAttribute() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// RuntimeHelpers
|
||||
// This class defines entry point for multi-core JIT API
|
||||
//
|
||||
// Date: Oct 2010
|
||||
//
|
||||
namespace System.Runtime {
|
||||
|
||||
using System;
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
using System.Runtime;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#if FEATURE_MULTICOREJIT
|
||||
|
||||
public static class ProfileOptimization
|
||||
{
|
||||
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
|
||||
[SecurityCritical]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
internal static extern void InternalSetProfileRoot(string directoryPath);
|
||||
|
||||
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
|
||||
[SecurityCritical]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
internal static extern void InternalStartProfile(string profile, IntPtr ptrNativeAssemblyLoadContext);
|
||||
|
||||
[SecurityCritical]
|
||||
public static void SetProfileRoot(string directoryPath)
|
||||
{
|
||||
InternalSetProfileRoot(directoryPath);
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static void StartProfile(string profile)
|
||||
{
|
||||
InternalStartProfile(profile, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class AsyncStateMachineAttribute : StateMachineAttribute
|
||||
{
|
||||
public AsyncStateMachineAttribute(Type stateMachineType)
|
||||
: base(stateMachineType)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
|
||||
public sealed class CallerFilePathAttribute : Attribute
|
||||
{
|
||||
public CallerFilePathAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
|
||||
public sealed class CallerLineNumberAttribute : Attribute
|
||||
{
|
||||
public CallerLineNumberAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
|
||||
public sealed class CallerMemberNameAttribute : Attribute
|
||||
{
|
||||
public CallerMemberNameAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,59 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
/*============================================================
|
||||
**
|
||||
** Class: FormattableStringFactory
|
||||
**
|
||||
**
|
||||
** Purpose: implementation of the FormattableStringFactory
|
||||
** class.
|
||||
**
|
||||
===========================================================*/
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
/// <summary>
|
||||
/// A factory type used by compilers to create instances of the type <see cref="FormattableString"/>.
|
||||
/// </summary>
|
||||
public static class FormattableStringFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a <see cref="FormattableString"/> from a composite format string and object
|
||||
/// array containing zero or more objects to format.
|
||||
/// </summary>
|
||||
public static FormattableString Create(string format, params object[] arguments)
|
||||
{
|
||||
if (format == null)
|
||||
{
|
||||
throw new ArgumentNullException("format");
|
||||
}
|
||||
|
||||
if (arguments == null)
|
||||
{
|
||||
throw new ArgumentNullException("arguments");
|
||||
}
|
||||
|
||||
return new ConcreteFormattableString(format, arguments);
|
||||
}
|
||||
|
||||
private sealed class ConcreteFormattableString : FormattableString
|
||||
{
|
||||
private readonly string _format;
|
||||
private readonly object[] _arguments;
|
||||
|
||||
internal ConcreteFormattableString(string format, object[] arguments)
|
||||
{
|
||||
_format = format;
|
||||
_arguments = arguments;
|
||||
}
|
||||
|
||||
public override string Format { get { return _format; } }
|
||||
public override object[] GetArguments() { return _arguments; }
|
||||
public override int ArgumentCount { get { return _arguments.Length; } }
|
||||
public override object GetArgument(int index) { return _arguments[index]; }
|
||||
public override string ToString(IFormatProvider formatProvider) { return string.Format(formatProvider, _format, _arguments); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||||
//
|
||||
// IAsyncStateMachine.cs
|
||||
//
|
||||
// <OWNER>stoub</OWNER>
|
||||
//
|
||||
// Represents state machines generated for asynchronous methods.
|
||||
//
|
||||
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents state machines generated for asynchronous methods.
|
||||
/// This type is intended for compiler use only.
|
||||
/// </summary>
|
||||
public interface IAsyncStateMachine
|
||||
{
|
||||
/// <summary>Moves the state machine to its next state.</summary>
|
||||
void MoveNext();
|
||||
/// <summary>Configures the state machine with a heap-allocated replica.</summary>
|
||||
/// <param name="stateMachine">The heap-allocated replica.</param>
|
||||
void SetStateMachine(IAsyncStateMachine stateMachine);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
|
||||
//
|
||||
// INotifyCompletion.cs
|
||||
//
|
||||
// <OWNER>stoub</OWNER>
|
||||
//
|
||||
// Interfaces used to represent instances that notify listeners of their completion via continuations.
|
||||
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
|
||||
using System;
|
||||
using System.Security;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an operation that will schedule continuations when the operation completes.
|
||||
/// </summary>
|
||||
public interface INotifyCompletion
|
||||
{
|
||||
/// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
|
||||
/// <param name="continuation">The action to invoke when the operation completes.</param>
|
||||
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
|
||||
void OnCompleted(Action continuation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents an awaiter used to schedule continuations when an await operation completes.
|
||||
/// </summary>
|
||||
public interface ICriticalNotifyCompletion : INotifyCompletion
|
||||
{
|
||||
/// <summary>Schedules the continuation action to be invoked when the instance completes.</summary>
|
||||
/// <param name="continuation">The action to invoke when the operation completes.</param>
|
||||
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
|
||||
/// <remarks>Unlike OnCompleted, UnsafeOnCompleted need not propagate ExecutionContext information.</remarks>
|
||||
[SecurityCritical]
|
||||
void UnsafeOnCompleted(Action continuation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class IteratorStateMachineAttribute : StateMachineAttribute
|
||||
{
|
||||
public IteratorStateMachineAttribute(Type stateMachineType)
|
||||
: base(stateMachineType)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
/*============================================================
|
||||
**
|
||||
** Attribute: ReferenceAssemblyAttribute
|
||||
**
|
||||
** Purpose: Identifies an assembly as being a "reference
|
||||
** assembly", meaning it contains public surface area but
|
||||
** no usable implementation. Reference assemblies
|
||||
** should be loadable for introspection, but not execution.
|
||||
**
|
||||
============================================================*/
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=false)]
|
||||
public sealed class ReferenceAssemblyAttribute : Attribute
|
||||
{
|
||||
private String _description; // Maybe ".NET FX v4.0 SP1, partial trust"?
|
||||
|
||||
public ReferenceAssemblyAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public ReferenceAssemblyAttribute(String description)
|
||||
{
|
||||
_description = description;
|
||||
}
|
||||
|
||||
public String Description
|
||||
{
|
||||
get { return _description; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*=============================================================================
|
||||
**
|
||||
** Class: RuntimeCompatibilityAttribute
|
||||
**
|
||||
**
|
||||
** Purpose: Mark up the program to indicate various legacy or new opt-in behaviors.
|
||||
**
|
||||
**
|
||||
=============================================================================*/
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
[AttributeUsage(AttributeTargets.Assembly, Inherited=false, AllowMultiple=false)]
|
||||
public sealed class RuntimeCompatibilityAttribute : Attribute
|
||||
{
|
||||
// fields
|
||||
private bool m_wrapNonExceptionThrows;
|
||||
|
||||
// constructors
|
||||
public RuntimeCompatibilityAttribute() {
|
||||
// legacy behavior is the default, and m_wrapNonExceptionThrows is implicitly
|
||||
// false thanks to the CLR's guarantee of zeroed memory.
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
// If a non-CLSCompliant exception (i.e. one that doesn't derive from System.Exception) is
|
||||
// thrown, should it be wrapped up in a System.Runtime.CompilerServices.RuntimeWrappedException
|
||||
// instance when presented to catch handlers?
|
||||
public bool WrapNonExceptionThrows {
|
||||
get {
|
||||
return m_wrapNonExceptionThrows;
|
||||
}
|
||||
set {
|
||||
m_wrapNonExceptionThrows = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
/*=============================================================================
|
||||
**
|
||||
** Class: RuntimeWrappedException
|
||||
**
|
||||
**
|
||||
** Purpose: The exception class uses to wrap all non-CLS compliant exceptions.
|
||||
**
|
||||
**
|
||||
=============================================================================*/
|
||||
|
||||
namespace System.Runtime.CompilerServices {
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Security.Permissions;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
[Serializable]
|
||||
public sealed class RuntimeWrappedException : Exception
|
||||
{
|
||||
private RuntimeWrappedException(Object thrownObject)
|
||||
: base(Environment.GetResourceString("RuntimeWrappedException")) {
|
||||
SetErrorCode(System.__HResults.COR_E_RUNTIMEWRAPPED);
|
||||
m_wrappedException = thrownObject;
|
||||
}
|
||||
|
||||
public Object WrappedException {
|
||||
get { return m_wrappedException; }
|
||||
}
|
||||
|
||||
private Object m_wrappedException;
|
||||
|
||||
[System.Security.SecurityCritical] // auto-generated_required
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
|
||||
if (info==null) {
|
||||
throw new ArgumentNullException("info");
|
||||
}
|
||||
Contract.EndContractBlock();
|
||||
base.GetObjectData(info, context);
|
||||
info.AddValue("WrappedException", m_wrappedException, typeof(Object));
|
||||
}
|
||||
|
||||
internal RuntimeWrappedException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context) {
|
||||
m_wrappedException = info.GetValue("WrappedException", typeof(Object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[Serializable, AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
||||
public class StateMachineAttribute : Attribute
|
||||
{
|
||||
public Type StateMachineType { get; private set; }
|
||||
|
||||
public StateMachineAttribute(Type stateMachineType)
|
||||
{
|
||||
this.StateMachineType = stateMachineType;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class TypeForwardedFromAttribute : Attribute
|
||||
{
|
||||
string assemblyFullName;
|
||||
|
||||
private TypeForwardedFromAttribute()
|
||||
{
|
||||
// Disallow default constructor
|
||||
}
|
||||
|
||||
|
||||
public TypeForwardedFromAttribute(string assemblyFullName)
|
||||
{
|
||||
if (String.IsNullOrEmpty(assemblyFullName))
|
||||
{
|
||||
throw new ArgumentNullException("assemblyFullName");
|
||||
}
|
||||
this.assemblyFullName = assemblyFullName;
|
||||
}
|
||||
|
||||
public string AssemblyFullName
|
||||
{
|
||||
get {
|
||||
return assemblyFullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
using System;
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)]
|
||||
public sealed class TypeForwardedToAttribute : Attribute
|
||||
{
|
||||
private Type _destination;
|
||||
|
||||
public TypeForwardedToAttribute(Type destination)
|
||||
{
|
||||
_destination = destination;
|
||||
}
|
||||
|
||||
public Type Destination
|
||||
{
|
||||
get {
|
||||
return _destination;
|
||||
}
|
||||
}
|
||||
#if false
|
||||
[System.Security.SecurityCritical]
|
||||
internal static TypeForwardedToAttribute[] GetCustomAttribute(RuntimeAssembly assembly)
|
||||
{
|
||||
Type[] types = null;
|
||||
RuntimeAssembly.GetForwardedTypes(assembly.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));
|
||||
|
||||
TypeForwardedToAttribute[] attributes = new TypeForwardedToAttribute[types.Length];
|
||||
for (int i = 0; i < types.Length; ++i)
|
||||
attributes[i] = new TypeForwardedToAttribute(types[i]);
|
||||
|
||||
return attributes;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
// ==++==
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
|
||||
//
|
||||
// YieldAwaitable.cs
|
||||
//
|
||||
// <OWNER>[....]</OWNER>
|
||||
//
|
||||
// Compiler-targeted type for switching back into the current execution context, e.g.
|
||||
//
|
||||
// await Task.Yield();
|
||||
// =====================
|
||||
// var $awaiter = Task.Yield().GetAwaiter();
|
||||
// if (!$awaiter.IsCompleted)
|
||||
// {
|
||||
// $builder.AwaitUnsafeOnCompleted(ref $awaiter, ref this);
|
||||
// return;
|
||||
// Label:
|
||||
// }
|
||||
// $awaiter.GetResult();
|
||||
//
|
||||
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
|
||||
using System;
|
||||
using System.Security;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Permissions;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
// NOTE: YieldAwaitable currently has no state; while developers are encouraged to use Task.Yield() to produce one,
|
||||
// no validation is performed to ensure that the developer isn't doing "await new YieldAwaitable()". Such validation
|
||||
// would require additional, useless state to be stored, and as this is a type in the CompilerServices namespace, and
|
||||
// as the above example isn't harmful, we take the cheaper approach of not validating anything.
|
||||
|
||||
/// <summary>Provides an awaitable context for switching into a target environment.</summary>
|
||||
/// <remarks>This type is intended for compiler use only.</remarks>
|
||||
public struct YieldAwaitable
|
||||
{
|
||||
/// <summary>Gets an awaiter for this <see cref="YieldAwaitable"/>.</summary>
|
||||
/// <returns>An awaiter for this awaitable.</returns>
|
||||
/// <remarks>This method is intended for compiler user rather than use directly in code.</remarks>
|
||||
public YieldAwaiter GetAwaiter() { return new YieldAwaiter(); }
|
||||
|
||||
/// <summary>Provides an awaiter that switches into a target environment.</summary>
|
||||
/// <remarks>This type is intended for compiler use only.</remarks>
|
||||
[HostProtection(Synchronization = true, ExternalThreading = true)]
|
||||
public struct YieldAwaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
/// <summary>Gets whether a yield is not required.</summary>
|
||||
/// <remarks>This property is intended for compiler user rather than use directly in code.</remarks>
|
||||
public bool IsCompleted { get { return false; } } // yielding is always required for YieldAwaiter, hence false
|
||||
|
||||
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
|
||||
/// <param name="continuation">The action to invoke asynchronously.</param>
|
||||
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
|
||||
[SecuritySafeCritical]
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
QueueContinuation(continuation, flowContext: true);
|
||||
}
|
||||
|
||||
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
|
||||
/// <param name="continuation">The action to invoke asynchronously.</param>
|
||||
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
|
||||
[SecurityCritical]
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
QueueContinuation(continuation, flowContext: false);
|
||||
}
|
||||
|
||||
/// <summary>Posts the <paramref name="continuation"/> back to the current context.</summary>
|
||||
/// <param name="continuation">The action to invoke asynchronously.</param>
|
||||
/// <param name="flowContext">true to flow ExecutionContext; false if flowing is not required.</param>
|
||||
/// <exception cref="System.ArgumentNullException">The <paramref name="continuation"/> argument is null (Nothing in Visual Basic).</exception>
|
||||
[SecurityCritical]
|
||||
private static void QueueContinuation(Action continuation, bool flowContext)
|
||||
{
|
||||
// Validate arguments
|
||||
if (continuation == null) throw new ArgumentNullException("continuation");
|
||||
Contract.EndContractBlock();
|
||||
|
||||
#if !MONO
|
||||
if (TplEtwProvider.Log.IsEnabled())
|
||||
{
|
||||
continuation = OutputCorrelationEtwEvent(continuation);
|
||||
}
|
||||
#endif
|
||||
// Get the current SynchronizationContext, and if there is one,
|
||||
// post the continuation to it. However, treat the base type
|
||||
// as if there wasn't a SynchronizationContext, since that's what it
|
||||
// logically represents.
|
||||
var syncCtx = SynchronizationContext.CurrentNoFlow;
|
||||
if (syncCtx != null && syncCtx.GetType() != typeof(SynchronizationContext))
|
||||
{
|
||||
syncCtx.Post(s_sendOrPostCallbackRunAction, continuation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we're targeting the default scheduler, queue to the thread pool, so that we go into the global
|
||||
// queue. As we're going into the global queue, we might as well use QUWI, which for the global queue is
|
||||
// just a tad faster than task, due to a smaller object getting allocated and less work on the execution path.
|
||||
TaskScheduler scheduler = TaskScheduler.Current;
|
||||
if (scheduler == TaskScheduler.Default)
|
||||
{
|
||||
if (flowContext)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(s_waitCallbackRunAction, continuation);
|
||||
}
|
||||
else
|
||||
{
|
||||
ThreadPool.UnsafeQueueUserWorkItem(s_waitCallbackRunAction, continuation);
|
||||
}
|
||||
}
|
||||
// We're targeting a custom scheduler, so queue a task.
|
||||
else
|
||||
{
|
||||
Task.Factory.StartNew(continuation, default(CancellationToken), TaskCreationOptions.PreferFairness, scheduler);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if !MONO
|
||||
private static Action OutputCorrelationEtwEvent(Action continuation)
|
||||
{
|
||||
int continuationId = Task.NewId();
|
||||
Task currentTask = Task.InternalCurrent;
|
||||
// fire the correlation ETW event
|
||||
TplEtwProvider.Log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, (currentTask != null) ? currentTask.Id : 0, continuationId);
|
||||
|
||||
return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, () =>
|
||||
{
|
||||
var etwLog = TplEtwProvider.Log;
|
||||
etwLog.TaskWaitContinuationStarted(continuationId);
|
||||
|
||||
// ETW event for Task Wait End.
|
||||
Guid prevActivityId = new Guid();
|
||||
// Ensure the continuation runs under the correlated activity ID generated above
|
||||
if (etwLog.TasksSetActivityIds)
|
||||
EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(continuationId), out prevActivityId);
|
||||
|
||||
// Invoke the original continuation provided to OnCompleted.
|
||||
continuation();
|
||||
// Restore activity ID
|
||||
|
||||
if (etwLog.TasksSetActivityIds)
|
||||
EventSource.SetCurrentThreadActivityId(prevActivityId);
|
||||
|
||||
etwLog.TaskWaitContinuationComplete(continuationId);
|
||||
});
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>WaitCallback that invokes the Action supplied as object state.</summary>
|
||||
private static readonly WaitCallback s_waitCallbackRunAction = RunAction;
|
||||
/// <summary>SendOrPostCallback that invokes the Action supplied as object state.</summary>
|
||||
private static readonly SendOrPostCallback s_sendOrPostCallbackRunAction = RunAction;
|
||||
|
||||
/// <summary>Runs an Action delegate provided as state.</summary>
|
||||
/// <param name="state">The Action delegate to invoke.</param>
|
||||
private static void RunAction(object state) { ((Action)state)(); }
|
||||
|
||||
/// <summary>Ends the await operation.</summary>
|
||||
public void GetResult() {} // Nop. It exists purely because the compiler pattern demands it.
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user