Skip to content

Commit

Permalink
Add support for a callback function when GC stops/starts the world
Browse files Browse the repository at this point in the history
This allow the code to exclude the thread when Instruments is attached to be compiled as part of the application instead of in Mono
  • Loading branch information
martinpotter committed Jan 24, 2020
1 parent 1e4c2e9 commit 157739a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mono/metadata/sgen-stw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 157739a

Please sign in to comment.