From 00cffe2f7f2595013c84d353901621702922112e Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 27 Jul 2021 15:12:53 +0200 Subject: [PATCH 1/2] [ObjCRuntime] Implement Runtime.UseAutoreleasePoolInThreadPool for .NET. The getter just returns the runtime appcontext value, while the setter throws a PlatformNotSupportedException pointing at our documentation about how to change the value at build time. --- src/ObjCRuntime/Runtime.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 8459bc18b752..0a367de47a0b 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -281,8 +281,7 @@ unsafe static void Initialize (InitializationOptions* options) #endif InitializePlatform (options); -#if !XAMMAC_SYSTEM_MONO && !NET_TODO - // NET_TODO: https://github.com/dotnet/runtime/issues/32543 +#if !XAMMAC_SYSTEM_MONO && !NET UseAutoreleasePoolInThreadPool = true; #endif IsARM64CallingConvention = GetIsARM64CallingConvention (); // Can only be done after Runtime.Arch is set (i.e. InitializePlatform has been called). @@ -301,8 +300,19 @@ unsafe static void Initialize (InitializationOptions* options) #endif } -#if !XAMMAC_SYSTEM_MONO && !NET_TODO - // NET_TODO: https://github.com/dotnet/runtime/issues/32543 +#if !XAMMAC_SYSTEM_MONO +#if NET + [EditorBrowsable (EditorBrowsableState.Never)] + [Obsolete ("Use the 'AutoreleasePoolSupport' MSBuild property instead: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/threading#autoreleasepool-for-managed-threads")] + public static bool UseAutoreleasePoolInThreadPool { + get { + return AppContext.TryGetSwitch ("System.Threading.Thread.EnableAutoreleasePool", out var enabled) && enabled; + } + set { + throw new PlatformNotSupportedException ("Use the 'AutoreleasePoolSupport' MSBuild property instead: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/threading#autoreleasepool-for-managed-threads"); + } + } +#else static bool has_autoreleasepool_in_thread_pool; public static bool UseAutoreleasePoolInThreadPool { get { @@ -319,6 +329,7 @@ static bool ThreadPoolDispatcher (Func callback) using (var pool = new NSAutoreleasePool ()) return callback (); } +#endif // NET #endif #if MONOMAC From 4374c6913f8f2391c84f0e17c2f62cb942721db7 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 28 Jul 2021 09:10:45 +0200 Subject: [PATCH 2/2] Correct obsolete message. --- src/ObjCRuntime/Runtime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 0a367de47a0b..cefe45c9d256 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -303,7 +303,7 @@ unsafe static void Initialize (InitializationOptions* options) #if !XAMMAC_SYSTEM_MONO #if NET [EditorBrowsable (EditorBrowsableState.Never)] - [Obsolete ("Use the 'AutoreleasePoolSupport' MSBuild property instead: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/threading#autoreleasepool-for-managed-threads")] + [Obsolete ("Use the 'AutoreleasePoolSupport' MSBuild property instead: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/threading#autoreleasepool-for-managed-threads.")] public static bool UseAutoreleasePoolInThreadPool { get { return AppContext.TryGetSwitch ("System.Threading.Thread.EnableAutoreleasePool", out var enabled) && enabled;