From 1c1a72714392aee438919a185b8f4c0d4c42aeab Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 14 Nov 2022 19:09:15 +0100 Subject: [PATCH] [runtime] Use the built-in support in MonoVM for autorelease pools on threadpool threads. Fixes #11788. MonoVM in .NET 6+ supports automatic autorelease pools on threadpool threads just like CoreCLR does, so we can remove our custom mono profiler hooks to accomplish this. Fixes https://github.com/xamarin/xamarin-macios/issues/11788. --- runtime/exports.t4 | 1 + runtime/monovm-bridge.m | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/runtime/exports.t4 b/runtime/exports.t4 index 336f850fd95c..885cf9ba42c1 100644 --- a/runtime/exports.t4 +++ b/runtime/exports.t4 @@ -255,6 +255,7 @@ "MonoProfileThreadFunc", "end" ) { XamarinRuntime = RuntimeMode.MonoVM, + Mode = DotNetMode.OnlyLegacy, }, new Export ("void", "mono_profiler_install_gc", diff --git a/runtime/monovm-bridge.m b/runtime/monovm-bridge.m index 961c748e6d7d..904dae8acfe6 100644 --- a/runtime/monovm-bridge.m +++ b/runtime/monovm-bridge.m @@ -235,6 +235,7 @@ * and create a pool that spans the thread's entire lifetime. */ +#if !DOTNET static CFMutableDictionaryRef xamarin_thread_hash = NULL; static pthread_mutex_t thread_hash_lock = PTHREAD_MUTEX_INITIALIZER; @@ -296,14 +297,18 @@ // COOP: no managed memory access: any mode. xamarin_thread_finish (NULL); } +#endif // !DOTNET void xamarin_install_nsautoreleasepool_hooks () { + // No need to do anything here for CoreCLR. +#if !DOTNET // COOP: executed at startup (and no managed memory access): any mode. xamarin_thread_hash = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, NULL, NULL); mono_profiler_install_thread (thread_start, thread_end); +#endif // !DOTNET } void