Skip to content

Commit

Permalink
[ObjCRuntime] Implement Runtime.UseAutoreleasePoolInThreadPool for .NET.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rolfbjarne committed Jul 27, 2021
1 parent edc088a commit 00cffe2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ unsafe static void Initialize (InitializationOptions* options)
#endif
InitializePlatform (options);

#if !XAMMAC_SYSTEM_MONO && !NET_TODO
// NET_TODO: https:/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).
Expand All @@ -301,8 +300,19 @@ unsafe static void Initialize (InitializationOptions* options)
#endif
}

#if !XAMMAC_SYSTEM_MONO && !NET_TODO
// NET_TODO: https:/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 {
Expand All @@ -319,6 +329,7 @@ static bool ThreadPoolDispatcher (Func<bool> callback)
using (var pool = new NSAutoreleasePool ())
return callback ();
}
#endif // NET
#endif

#if MONOMAC
Expand Down

0 comments on commit 00cffe2

Please sign in to comment.