2009-02-04 Marek Habersack <mhabersack@novell.com>
[mono.git] / mono / metadata / profiler.c
index 28851576d3122611a2afabcae0bf86b01e9b4d11..a07fb9510a6539cc9fa332e6c70e3d4304d76c88 100644 (file)
@@ -4,8 +4,8 @@
  * Author:
  *   Paolo Molaro (lupus@ximian.com)
  *
- * (C) 2001-2003 Ximian, Inc.
- * (C) 2003-2006 Novell, Inc.
+ * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
  */
 
 #include "config.h"
@@ -78,6 +78,8 @@ static MonoProfileFunc shutdown_callback;
 static MonoProfileGCFunc        gc_event;
 static MonoProfileGCResizeFunc  gc_heap_resize;
 
+static MonoProfileFunc          runtime_initialized_event;
+
 #define mono_profiler_coverage_lock() EnterCriticalSection (&profiler_coverage_mutex)
 #define mono_profiler_coverage_unlock() LeaveCriticalSection (&profiler_coverage_mutex)
 static CRITICAL_SECTION profiler_coverage_mutex;
@@ -532,6 +534,19 @@ mono_profiler_install_gc (MonoProfileGCFunc callback, MonoProfileGCResizeFunc he
        gc_heap_resize = heap_resize_callback;
 }
 
+void
+mono_profiler_install_runtime_initialized (MonoProfileFunc runtime_initialized_callback)
+{
+       runtime_initialized_event = runtime_initialized_callback;
+}
+
+void
+mono_profiler_runtime_initialized (void) {
+       if (runtime_initialized_event)
+               runtime_initialized_event (current_profiler);
+}
+
+
 static GHashTable *coverage_hash = NULL;
 
 MonoProfileCoverageInfo* 
@@ -1433,7 +1448,11 @@ simple_shutdown (MonoProfiler *prof)
        GSList *tmp;
        char *str;
        gint32 see_shutdown_done;
-       
+
+#ifndef PLATFORM_WIN32
+       mono_thread_attach(mono_get_root_domain());
+#endif
+
        // Make sure we execute simple_shutdown only once
        see_shutdown_done = InterlockedExchange(& simple_shutdown_done, TRUE);
        if (see_shutdown_done)