summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2019-04-01 18:29:35 -0400
committerDan Moseley <danmose@microsoft.com>2019-04-01 15:29:35 -0700
commitf406d721bc1edaa6fa842f14e262b74ea3fa4d4e (patch)
tree167277bafdb2b98b7a78e03761d1a8a256d6cdb0
parentaf2fd41ca67da6c90dea190cc9df5d9ebb0ea973 (diff)
downloadcoreclr-f406d721bc1edaa6fa842f14e262b74ea3fa4d4e.tar.gz
coreclr-f406d721bc1edaa6fa842f14e262b74ea3fa4d4e.tar.bz2
coreclr-f406d721bc1edaa6fa842f14e262b74ea3fa4d4e.zip
Nullable: SynchronizationContext (#23634)
-rw-r--r--src/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs3
-rw-r--r--src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs7
-rw-r--r--src/System.Private.CoreLib/src/System/Delegate.cs4
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs1
-rw-r--r--src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs19
5 files changed, 19 insertions, 15 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs b/src/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs
index b96914ab2c..2257ad6b03 100644
--- a/src/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs
+++ b/src/System.Private.CoreLib/shared/System/Threading/SendOrPostCallback.cs
@@ -2,7 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Threading
{
- public delegate void SendOrPostCallback(object state);
+ public delegate void SendOrPostCallback(object? state);
}
diff --git a/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs b/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs
index 93555e9072..8f4eec1865 100644
--- a/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs
+++ b/src/System.Private.CoreLib/shared/System/Threading/SynchronizationContext.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Threading
{
public partial class SynchronizationContext
@@ -20,9 +21,9 @@ namespace System.Threading
public bool IsWaitNotificationRequired() => _requireWaitNotification;
- public virtual void Send(SendOrPostCallback d, object state) => d(state);
+ public virtual void Send(SendOrPostCallback d, object? state) => d(state);
- public virtual void Post(SendOrPostCallback d, object state) => ThreadPool.QueueUserWorkItem(s => s.d(s.state), (d, state), preferLocal: false);
+ public virtual void Post(SendOrPostCallback d, object? state) => ThreadPool.QueueUserWorkItem(s => s.d(s.state), (d, state), preferLocal: false);
/// <summary>
/// Optional override for subclasses, for responding to notification that operation is starting.
@@ -55,7 +56,7 @@ namespace System.Threading
return WaitHandle.WaitMultipleIgnoringSyncContext(waitHandles, waitAll, millisecondsTimeout);
}
- public static void SetSynchronizationContext(SynchronizationContext syncContext) => Thread.CurrentThread._synchronizationContext = syncContext;
+ public static void SetSynchronizationContext(SynchronizationContext? syncContext) => Thread.CurrentThread._synchronizationContext = syncContext;
public virtual SynchronizationContext CreateCopy() => new SynchronizationContext();
}
diff --git a/src/System.Private.CoreLib/src/System/Delegate.cs b/src/System.Private.CoreLib/src/System/Delegate.cs
index 20d934cd5c..77dcea5a76 100644
--- a/src/System.Private.CoreLib/src/System/Delegate.cs
+++ b/src/System.Private.CoreLib/src/System/Delegate.cs
@@ -574,9 +574,9 @@ namespace System
}
// V1 API.
- public static Delegate? CreateDelegate(Type type, MethodInfo method)
+ public static Delegate CreateDelegate(Type type, MethodInfo method)
{
- return CreateDelegate(type, method, true);
+ return CreateDelegate(type, method, throwOnBindFailure: true)!; // Cannot return null because it would have thrown
}
internal static Delegate? CreateDelegateInternal(RuntimeType rtType, RuntimeMethodInfo rtMethod, object? firstArgument, DelegateBindingFlags flags)
diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs
index e26d9b7b70..db110279db 100644
--- a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.CoreCLR.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
namespace System.Threading
{
public partial class SynchronizationContext
diff --git a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs
index a9f0727771..b04f93e516 100644
--- a/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs
+++ b/src/System.Private.CoreLib/src/System/Threading/SynchronizationContext.Uap.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+#nullable enable
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Reflection;
@@ -11,11 +12,11 @@ namespace System.Threading
{
public partial class SynchronizationContext
{
- public static SynchronizationContext Current
+ public static SynchronizationContext? Current
{
get
{
- SynchronizationContext context = Thread.CurrentThread._synchronizationContext;
+ SynchronizationContext? context = Thread.CurrentThread._synchronizationContext;
if (context == null && ApplicationModel.IsUap)
context = GetWinRTContext();
@@ -24,7 +25,7 @@ namespace System.Threading
}
}
- private static SynchronizationContext GetWinRTContext()
+ private static SynchronizationContext? GetWinRTContext()
{
Debug.Assert(Environment.IsWinRTSupported);
Debug.Assert(ApplicationModel.IsUap);
@@ -39,14 +40,14 @@ namespace System.Threading
// So, we check the VM to see if the current thread has a dispatcher; if it does, we pass that along to
// System.Runtime.WindowsRuntime to get a corresponding SynchronizationContext.
//
- object dispatcher = GetWinRTDispatcherForCurrentThread();
+ object? dispatcher = GetWinRTDispatcherForCurrentThread();
if (dispatcher != null)
return GetWinRTSynchronizationContext(dispatcher);
return null;
}
- private static Func<object, SynchronizationContext> s_createSynchronizationContextDelegate;
+ private static Func<object, SynchronizationContext>? s_createSynchronizationContextDelegate;
private static SynchronizationContext GetWinRTSynchronizationContext(object dispatcher)
{
@@ -55,23 +56,23 @@ namespace System.Threading
// It would be better if we could just implement WinRTSynchronizationContextFactory in mscorlib, but we can't, because
// we can do very little with WinRT stuff in mscorlib.
//
- Func<object, SynchronizationContext> createSynchronizationContextDelegate = s_createSynchronizationContextDelegate;
+ Func<object, SynchronizationContext>? createSynchronizationContextDelegate = s_createSynchronizationContextDelegate;
if (createSynchronizationContextDelegate == null)
{
Type factoryType = Type.GetType("System.Threading.WinRTSynchronizationContextFactory, System.Runtime.WindowsRuntime", throwOnError: true);
// Create an instance delegate for the Create static method
MethodInfo createMethodInfo = factoryType.GetMethod("Create", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
- createSynchronizationContextDelegate = (Func<object, SynchronizationContext>)Delegate.CreateDelegate(typeof(Func<object, SynchronizationContext>), createMethodInfo, /* throwOnBindFailure */ true);
+ createSynchronizationContextDelegate = (Func<object, SynchronizationContext>)Delegate.CreateDelegate(typeof(Func<object, SynchronizationContext>), createMethodInfo);
s_createSynchronizationContextDelegate = createSynchronizationContextDelegate;
}
- return s_createSynchronizationContextDelegate(dispatcher);
+ return createSynchronizationContextDelegate(dispatcher);
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Interface)]
- private static extern object GetWinRTDispatcherForCurrentThread();
+ private static extern object? GetWinRTDispatcherForCurrentThread();
}
}