move the call to mono_gc_base_init into mono_debug_init
authorChris Toshok <toshok@gmail.com>
Thu, 9 Sep 2010 17:08:59 +0000 (10:08 -0700)
committerChris Toshok <toshok@gmail.com>
Thu, 9 Sep 2010 18:53:50 +0000 (11:53 -0700)
mono_debug_init is a public embedding interface and calls into
mono_debugger_initialize, which registers a GC root.  driver.c calls
mono_gc_base_init before calling mono_debug_init for this reason, but
that's not an option for embedding (as mono_gc_base_init is internal.)

since mono_gc_base_init is idempotent, just add a call to
mono_debug_init (and remove the driver.c call).  Document (in sgen-gc
and sgen-gc.h) the fact that although mono_gc_base_init is idempotent,
changing LOCK_INIT to something non-idempotent will break this.

mono/metadata/mono-debug.c
mono/metadata/sgen-gc.c
mono/metadata/sgen-gc.h
mono/mini/driver.c

index 92c70c33963275a2827e4268f9ff9c8bd51e3304..1894c1199319b47aa1648158b0477d777ac65f4b 100644 (file)
@@ -228,6 +228,12 @@ mono_debug_init (MonoDebugFormat format)
        mono_debug_initialized = TRUE;
        mono_debug_format = format;
 
+       /*
+        * This must be called before mono_debugger_initialize(), because the
+        * latter registers GC roots.
+        */
+       mono_gc_base_init ();
+
        mono_debugger_initialize (_mono_debug_using_mono_debugger);
 
        mono_debugger_lock ();
index e84b7b880c66969f36d25ef947b254c9fd106dc6..e945864a6a5b98e83ad2cf1a20ac063bb694cc8f 100644 (file)
@@ -6357,6 +6357,10 @@ mono_gc_base_init (void)
        char *major_collector = NULL;
        struct sigaction sinfo;
 
+       /* the gc_initialized guard seems to imply this method is
+          idempotent, but LOCK_INIT(gc_mutex) might not be.  It's
+          defined in sgen-gc.h as nothing, so there's no danger at
+          present. */
        LOCK_INIT (gc_mutex);
        LOCK_GC;
        if (gc_initialized) {
index d41bf3271a529d459d73c625b14aff04f6a0ff81..5e99839fdaeae6de33212011802bc51669921c0a 100644 (file)
@@ -185,6 +185,8 @@ const static int restart_signal_num = SIGXCPU;
  * Recursion is not allowed for the thread lock.
  */
 #define LOCK_DECLARE(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
+/* if changing LOCK_INIT to something that isn't idempotent, look at
+   its use in mono_gc_base_init in sgen-gc.c */
 #define LOCK_INIT(name)
 #define LOCK_GC pthread_mutex_lock (&gc_mutex)
 #define UNLOCK_GC pthread_mutex_unlock (&gc_mutex)
index fa38cb7a04d370ce1fafb2e95ca72e842b766b9a..de8050e4f2c213a362649c51de3a54ad777d83f9 100644 (file)
@@ -1698,12 +1698,6 @@ mono_main (int argc, char* argv[])
        }
 #endif
 
-       /*
-        * This must be called before mono_debug_init(), because the
-        * latter registers GC roots.
-        */
-       mono_gc_base_init ();
-
        if (action == DO_DEBUGGER) {
                enable_debugging = TRUE;