[gc] Make mono_gc_init_finalizer_thread a public API
authorAleksey Kliger <alklig@microsoft.com>
Wed, 18 Mar 2020 20:38:52 +0000 (16:38 -0400)
committerAleksey Kliger <aleksey@lambdageek.org>
Tue, 24 Mar 2020 01:10:19 +0000 (21:10 -0400)
It was already used by Xamarin.iOS but wasn't in a public header and required
compiling with --disable-visibility-hidden in order to dlsym the symbol.

If --with-lazy-gc-thread-creation is used, embedders must call this function to
create the finalizer therad.  Otherwise the function does nothing and the
runtime will create the finalizer thread automatically.

src/mono/mono/metadata/gc.c
src/mono/mono/metadata/mono-gc.h

index d9fe1af..f81963b 100644 (file)
@@ -999,17 +999,32 @@ finalizer_thread (gpointer unused)
        return 0;
 }
 
-#ifndef LAZY_GC_THREAD_CREATION
-static
-#endif
-void
-mono_gc_init_finalizer_thread (void)
+static void
+init_finalizer_thread (void)
 {
        ERROR_DECL (error);
        gc_thread = mono_thread_create_internal (mono_domain_get (), (gpointer)finalizer_thread, NULL, MONO_THREAD_CREATE_FLAGS_NONE, error);
        mono_error_assert_ok (error);
 }
 
+/**
+ * mono_gc_init_finalizer_thread:
+ *
+ * If the runtime is compiled with --with-lazy-gc-thread-creation, this
+ * function must be called by embedders to create the finalizer. Otherwise, the
+ * function does nothing and the runtime creates the finalizer thread
+ * automatically.
+ */
+void
+mono_gc_init_finalizer_thread (void)
+{
+#ifndef LAZY_GC_THREAD_CREATION
+       /* do nothing */
+#else
+       init_finalizer_thread ();
+#endif
+}
+
 static void
 reference_queue_mutex_init (void)
 {
@@ -1048,7 +1063,7 @@ mono_gc_init (void)
 
 #ifndef LAZY_GC_THREAD_CREATION
        if (!mono_runtime_get_no_exec ())
-               mono_gc_init_finalizer_thread ();
+               init_finalizer_thread ();
 #endif
 }
 
index 86111ac..72c768e 100644 (file)
@@ -123,6 +123,9 @@ MONO_API int    mono_gc_invoke_finalizers (void);
 /* heap walking is only valid in the pre-stop-world event callback */
 MONO_API int    mono_gc_walk_heap        (int flags, MonoGCReferences callback, void *data);
 
+MONO_API MONO_RT_EXTERNAL_ONLY void
+mono_gc_init_finalizer_thread (void);
+
 MONO_END_DECLS
 
 #endif /* __METADATA_MONO_GC_H__ */