From 157739a68fff8b098377550ca928c442372f962a Mon Sep 17 00:00:00 2001 From: Martin Potter Date: Fri, 11 Oct 2019 10:59:14 -0700 Subject: [PATCH] Add support for a callback function when GC stops/starts the world This allow the code to exclude the thread when Instruments is attached to be compiled as part of the application instead of in Mono --- mono/metadata/sgen-stw.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mono/metadata/sgen-stw.c b/mono/metadata/sgen-stw.c index 737e0326ea3a..fffaeb39cb61 100644 --- a/mono/metadata/sgen-stw.c +++ b/mono/metadata/sgen-stw.c @@ -28,6 +28,14 @@ #include "utils/mono-threads.h" #include "utils/mono-threads-debug.h" +MONO_API void mono_set_gc_start_stop_notification_function(void (*func) (uint8_t)); +static void (*GCStartStopNotificationFunction) (uint8_t) = NULL; + +void mono_set_gc_start_stop_notification_function(void (*func) (uint8_t)) +{ + GCStartStopNotificationFunction = func; +} + #define TV_DECLARE SGEN_TV_DECLARE #define TV_GETTIME SGEN_TV_GETTIME #define TV_ELAPSED SGEN_TV_ELAPSED @@ -117,6 +125,9 @@ sgen_client_stop_world (int generation, gboolean serial_collection) /* We start to scan after locks are taking, this ensures we won't be interrupted. */ sgen_process_togglerefs (); + if (GCStartStopNotificationFunction != NULL) + GCStartStopNotificationFunction(0); + sgen_global_stop_count++; SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer) (gsize) mono_native_thread_id_get ()); TV_GETTIME (stop_world_time); @@ -162,6 +173,9 @@ sgen_client_restart_world (int generation, gboolean serial_collection, gint64 *s TV_GETTIME (start_handshake); + if (GCStartStopNotificationFunction != NULL) + GCStartStopNotificationFunction(1); + sgen_unified_suspend_restart_world (); TV_GETTIME (end_sw);