From 306969822f9c52e4e18027ad49764d3af4950e2b Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Fri, 4 Sep 2020 15:49:04 -0400 Subject: [PATCH 1/5] System.Threading.ThreadPool enable platform attributes --- src/libraries/System.Threading.ThreadPool/Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Threading.ThreadPool/Directory.Build.props b/src/libraries/System.Threading.ThreadPool/Directory.Build.props index 63f02a0f817ef..d68d22c1b917f 100644 --- a/src/libraries/System.Threading.ThreadPool/Directory.Build.props +++ b/src/libraries/System.Threading.ThreadPool/Directory.Build.props @@ -2,5 +2,6 @@ Microsoft + true \ No newline at end of file From 7d07b8ca0a51f900b51880f77432bb71739fe396 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Fri, 4 Sep 2020 15:49:19 -0400 Subject: [PATCH 2/5] Mark System.Threading.ThreadPool APIs unsupported on browser --- .../src/System/Threading/ThreadPool.CoreCLR.cs | 2 ++ .../src/System/Threading/ThreadPool.Portable.cs | 2 ++ .../src/System/Threading/ThreadPool.cs | 9 +++++++++ .../ref/System.Threading.ThreadPool.cs | 10 ++++++++++ .../src/System/Threading/ThreadPool.Mono.cs | 2 ++ 5 files changed, 25 insertions(+) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index 59fecc735dd7b..19364410b6465 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -14,6 +14,7 @@ using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -352,6 +353,7 @@ public static bool BindHandle(IntPtr osHandle) return BindIOCompletionCallbackNative(osHandle); } + [UnsupportedOSPlatform("browser")] public static bool BindHandle(SafeHandle osHandle) { if (osHandle == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs index 83ef4df898c02..7b49045defd23 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using Microsoft.Win32.SafeHandles; +using System.Runtime.Versioning; namespace System.Threading { @@ -13,6 +14,7 @@ namespace System.Threading /// /// An object representing the registration of a via . /// + [UnsupportedOSPlatform("browser")] public sealed class RegisteredWaitHandle : MarshalByRefObject { internal RegisteredWaitHandle(WaitHandle waitHandle, _ThreadPoolWaitOrTimerCallback callbackHelper, diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.cs index 4bcf665b9a6ca..55b149d893686 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPool.cs @@ -17,6 +17,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading.Tasks; +using System.Runtime.Versioning; using Internal.Runtime.CompilerServices; namespace System.Threading @@ -950,6 +951,7 @@ public static partial class ThreadPool }; [CLSCompliant(false)] + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle RegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -964,6 +966,7 @@ public static RegisteredWaitHandle RegisterWaitForSingleObject( } [CLSCompliant(false)] + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -977,6 +980,7 @@ public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, millisecondsTimeOutInterval, executeOnlyOnce, false); } + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle RegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -990,6 +994,7 @@ public static RegisteredWaitHandle RegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, true); } + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -1003,6 +1008,7 @@ public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, false); } + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle RegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -1018,6 +1024,7 @@ public static RegisteredWaitHandle RegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, true); } + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -1033,6 +1040,7 @@ public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)millisecondsTimeOutInterval, executeOnlyOnce, false); } + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle RegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, @@ -1049,6 +1057,7 @@ bool executeOnlyOnce return RegisterWaitForSingleObject(waitObject, callBack, state, (uint)tm, executeOnlyOnce, true); } + [UnsupportedOSPlatform("browser")] public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject( WaitHandle waitObject, WaitOrTimerCallback callBack, diff --git a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs index b815c818c9492..4c494e68abb3b 100644 --- a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs +++ b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs @@ -10,6 +10,7 @@ public partial interface IThreadPoolWorkItem { void Execute(); } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public sealed partial class RegisteredWaitHandle : System.MarshalByRefObject { internal RegisteredWaitHandle() { } @@ -22,6 +23,7 @@ public static partial class ThreadPool public static int ThreadCount { get { throw null; } } [System.ObsoleteAttribute("ThreadPool.BindHandle(IntPtr) has been deprecated. Please use ThreadPool.BindHandle(SafeHandle) instead.", false)] public static bool BindHandle(System.IntPtr osHandle) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool BindHandle(System.Runtime.InteropServices.SafeHandle osHandle) { throw null; } public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads) { throw null; } public static void GetMaxThreads(out int workerThreads, out int completionPortThreads) { throw null; } @@ -29,10 +31,14 @@ public static partial class ThreadPool public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack) { throw null; } public static bool QueueUserWorkItem(System.Threading.WaitCallback callBack, object? state) { throw null; } public static bool QueueUserWorkItem(System.Action callBack, TState state, bool preferLocal) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, int millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, long millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, System.TimeSpan timeout, bool executeOnlyOnce) { throw null; } [System.CLSCompliantAttribute(false)] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } public static bool SetMaxThreads(int workerThreads, int completionPortThreads) { throw null; } public static bool SetMinThreads(int workerThreads, int completionPortThreads) { throw null; } @@ -41,10 +47,14 @@ public static partial class ThreadPool public static bool UnsafeQueueUserWorkItem(System.Threading.IThreadPoolWorkItem callBack, bool preferLocal) { throw null; } public static bool UnsafeQueueUserWorkItem(System.Threading.WaitCallback callBack, object? state) { throw null; } public static bool UnsafeQueueUserWorkItem(System.Action callBack, TState state, bool preferLocal) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, int millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, long millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, System.TimeSpan timeout, bool executeOnlyOnce) { throw null; } [System.CLSCompliantAttribute(false)] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static System.Threading.RegisteredWaitHandle UnsafeRegisterWaitForSingleObject(System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, uint millisecondsTimeOutInterval, bool executeOnlyOnce) { throw null; } } public delegate void WaitCallback(object? state); diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs index 49ee8ce9b8bd6..587becbbea5ee 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -32,6 +33,7 @@ public static bool BindHandle(IntPtr osHandle) throw new PlatformNotSupportedException(SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle } + [UnsupportedOSPlatform("browser")] public static bool BindHandle(SafeHandle osHandle) { throw new PlatformNotSupportedException(SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle From 87bc40f439c005a6a877172571279884b8016372 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Fri, 4 Sep 2020 17:33:34 -0400 Subject: [PATCH 3/5] System.Threading.ThreadPool Add Unsupported attribute to other ThreadPool files --- .../src/System/Threading/ThreadPool.CoreCLR.cs | 1 + .../src/System/Threading/ThreadPool.Browser.Mono.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index 19364410b6465..6b07d211173f4 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -160,6 +160,7 @@ private bool ValidHandle() => private static extern bool UnregisterWaitNative(IntPtr handle, SafeHandle? waitObject); } + [UnsupportedOSPlatform("browser")] public sealed class RegisteredWaitHandle : MarshalByRefObject { private readonly RegisteredWaitHandleSafe internalRegisteredWait; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs index 179e2f7a43c98..e71edb9c10f8a 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Browser.Mono.cs @@ -4,11 +4,13 @@ using System.Diagnostics; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.Versioning; using System.Diagnostics.CodeAnalysis; using Microsoft.Win32.SafeHandles; namespace System.Threading { + [UnsupportedOSPlatform("browser")] public sealed class RegisteredWaitHandle : MarshalByRefObject { internal RegisteredWaitHandle(WaitHandle waitHandle, _ThreadPoolWaitOrTimerCallback callbackHelper, From 70df91e8fe5af9f7683b198c72c6e01fb28124b7 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Tue, 8 Sep 2020 12:55:58 -0400 Subject: [PATCH 4/5] Remove Unsupported attributes from BindHandle --- .../src/System/Threading/ThreadPool.CoreCLR.cs | 1 - .../ref/System.Threading.ThreadPool.cs | 1 - .../src/System/Threading/ThreadPool.Mono.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index 6b07d211173f4..bd8cafec84e9f 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -354,7 +354,6 @@ public static bool BindHandle(IntPtr osHandle) return BindIOCompletionCallbackNative(osHandle); } - [UnsupportedOSPlatform("browser")] public static bool BindHandle(SafeHandle osHandle) { if (osHandle == null) diff --git a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs index 4c494e68abb3b..ee132e0fcaa6f 100644 --- a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs +++ b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs @@ -23,7 +23,6 @@ public static partial class ThreadPool public static int ThreadCount { get { throw null; } } [System.ObsoleteAttribute("ThreadPool.BindHandle(IntPtr) has been deprecated. Please use ThreadPool.BindHandle(SafeHandle) instead.", false)] public static bool BindHandle(System.IntPtr osHandle) { throw null; } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool BindHandle(System.Runtime.InteropServices.SafeHandle osHandle) { throw null; } public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads) { throw null; } public static void GetMaxThreads(out int workerThreads, out int completionPortThreads) { throw null; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs index 587becbbea5ee..47d68a9edcf98 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs @@ -33,7 +33,6 @@ public static bool BindHandle(IntPtr osHandle) throw new PlatformNotSupportedException(SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle } - [UnsupportedOSPlatform("browser")] public static bool BindHandle(SafeHandle osHandle) { throw new PlatformNotSupportedException(SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle From d95f3169d9424221e99f29f84dd0fbc49a910c53 Mon Sep 17 00:00:00 2001 From: Mitchell Hwang Date: Tue, 8 Sep 2020 12:58:01 -0400 Subject: [PATCH 5/5] Add windows Supported Attribute to BindHandle --- .../src/System/Threading/ThreadPool.CoreCLR.cs | 1 + .../ref/System.Threading.ThreadPool.cs | 1 + .../src/System/Threading/ThreadPool.Mono.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs index bd8cafec84e9f..86b6e4443cad8 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/ThreadPool.CoreCLR.cs @@ -354,6 +354,7 @@ public static bool BindHandle(IntPtr osHandle) return BindIOCompletionCallbackNative(osHandle); } + [SupportedOSPlatform("windows")] public static bool BindHandle(SafeHandle osHandle) { if (osHandle == null) diff --git a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs index ee132e0fcaa6f..5d4212129c175 100644 --- a/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs +++ b/src/libraries/System.Threading.ThreadPool/ref/System.Threading.ThreadPool.cs @@ -23,6 +23,7 @@ public static partial class ThreadPool public static int ThreadCount { get { throw null; } } [System.ObsoleteAttribute("ThreadPool.BindHandle(IntPtr) has been deprecated. Please use ThreadPool.BindHandle(SafeHandle) instead.", false)] public static bool BindHandle(System.IntPtr osHandle) { throw null; } + [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public static bool BindHandle(System.Runtime.InteropServices.SafeHandle osHandle) { throw null; } public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads) { throw null; } public static void GetMaxThreads(out int workerThreads, out int completionPortThreads) { throw null; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs index 47d68a9edcf98..11b23df388812 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/ThreadPool.Mono.cs @@ -33,6 +33,7 @@ public static bool BindHandle(IntPtr osHandle) throw new PlatformNotSupportedException(SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle } + [SupportedOSPlatform("windows")] public static bool BindHandle(SafeHandle osHandle) { throw new PlatformNotSupportedException(SR.Arg_PlatformNotSupported); // Replaced by ThreadPoolBoundHandle.BindHandle