[threads] Rework MonoThreadInfoCallbacks.thread_{register,detach,unregister} callback...
[mono.git] / mono / metadata / boehm-gc.c
index 42f4d16597d1b44d5cd5ac7c7faa7a8314387a41..4ad522d4dc3bdb39ef7ed0b8728d76960ddc9618 100644 (file)
@@ -57,9 +57,9 @@ static gboolean gc_initialized = FALSE;
 static mono_mutex_t mono_gc_lock;
 
 static void*
-boehm_thread_register (MonoThreadInfo* info, void *baseptr);
+boehm_thread_attach (MonoThreadInfo* info);
 static void
-boehm_thread_unregister (MonoThreadInfo *p);
+boehm_thread_detach_with_lock (MonoThreadInfo *p);
 static void
 boehm_thread_detach (MonoThreadInfo *p);
 static void
@@ -110,7 +110,6 @@ mono_gc_base_init (void)
 {
        MonoThreadInfoCallbacks cb;
        const char *env;
-       int dummy;
 
        if (gc_initialized)
                return;
@@ -239,16 +238,16 @@ mono_gc_base_init (void)
        }
 
        memset (&cb, 0, sizeof (cb));
-       cb.thread_register = boehm_thread_register;
-       cb.thread_unregister = boehm_thread_unregister;
+       cb.thread_attach = boehm_thread_attach;
        cb.thread_detach = boehm_thread_detach;
+       cb.thread_detach_with_lock = boehm_thread_detach_with_lock;
        cb.mono_method_is_critical = (gboolean (*)(void *))mono_runtime_is_critical_method;
 
        mono_threads_init (&cb, sizeof (MonoThreadInfo));
        mono_os_mutex_init (&mono_gc_lock);
        mono_os_mutex_init_recursive (&handle_section);
 
-       mono_thread_info_attach (&dummy);
+       mono_thread_info_attach ();
 
        GC_set_on_collection_event (on_gc_notification);
        GC_on_heap_resize = on_gc_heap_resize;
@@ -376,20 +375,14 @@ mono_gc_is_gc_thread (void)
        return GC_thread_is_registered ();
 }
 
-gboolean
-mono_gc_register_thread (void *baseptr)
-{
-       return mono_thread_info_attach (baseptr) != NULL;
-}
-
 static void*
-boehm_thread_register (MonoThreadInfo* info, void *baseptr)
+boehm_thread_attach (MonoThreadInfo* info)
 {
        struct GC_stack_base sb;
        int res;
 
        /* TODO: use GC_get_stack_base instead of baseptr. */
-       sb.mem_base = baseptr;
+       sb.mem_base = info->stack_end;
        res = GC_register_my_thread (&sb);
        if (res == GC_UNIMPLEMENTED)
            return NULL; /* Cannot happen with GC v7+. */
@@ -400,7 +393,7 @@ boehm_thread_register (MonoThreadInfo* info, void *baseptr)
 }
 
 static void
-boehm_thread_unregister (MonoThreadInfo *p)
+boehm_thread_detach_with_lock (MonoThreadInfo *p)
 {
        MonoNativeThreadId tid;