From 61cab3c6f524eb331805b77318d66dffc0229413 Mon Sep 17 00:00:00 2001 From: Martin Potter Date: Tue, 23 Apr 2019 10:18:20 -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 2af66e00b05b..9e31cafd7581 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) update_current_thread_stack (&generation); + 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); @@ -160,6 +171,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);