Wed Apr 9 15:19:41 CEST 2003 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / gc.c
index 7eb7447e9b7824d6a8ec8822777735f7255d1888..49f19786d6458089a978f1586fd3f5b5bfa0e315 100644 (file)
@@ -163,7 +163,7 @@ internal_domain_finalize (gpointer data) {
        MonoDomain *domain=(MonoDomain *)data;
        GHashTable *todo = g_hash_table_new (NULL, NULL);
 
-       mono_new_thread_init (GetCurrentThreadId (), todo, NULL);
+       mono_thread_new_init (GetCurrentThreadId (), todo, NULL);
        
 #if HAVE_BOEHM_GC
        GC_gcollect ();
@@ -249,6 +249,7 @@ ves_icall_System_GC_WaitForPendingFinalizers (void)
        MONO_ARCH_SAVE_REGS;
 }
 
+static CRITICAL_SECTION allocator_section;
 static CRITICAL_SECTION handle_section;
 static guint32 next_handle = 0;
 static gpointer *gc_handles = NULL;
@@ -438,7 +439,7 @@ static guint32 finalizer_thread (gpointer unused)
 {
        guint32 stack_start;
        
-       mono_new_thread_init (GetCurrentThreadId (), &stack_start, NULL);
+       mono_thread_new_init (GetCurrentThreadId (), &stack_start, NULL);
        
        while(!finished) {
                /* Wait to be notified that there's at least one
@@ -463,11 +464,45 @@ static guint32 finalizer_thread (gpointer unused)
  */
 #define ENABLE_FINALIZER_THREAD
 
+#ifdef WITH_INCLUDED_LIBGC
+/* from threads.c */
+extern void mono_gc_stop_world (void);
+extern void mono_gc_start_world (void);
+extern void mono_gc_push_all_stacks (void);
+
+static void mono_gc_lock (void)
+{
+       EnterCriticalSection (&allocator_section);
+}
+
+static void mono_gc_unlock (void)
+{
+       LeaveCriticalSection (&allocator_section);
+}
+
+static GCThreadFunctions mono_gc_thread_vtable = {
+       NULL,
+
+       mono_gc_lock,
+       mono_gc_unlock,
+
+       mono_gc_stop_world,
+       NULL,
+       mono_gc_push_all_stacks,
+       mono_gc_start_world
+};
+#endif /* WITH_INCLUDED_LIBGC */
+
 void mono_gc_init (void)
 {
        HANDLE gc_thread;
 
        InitializeCriticalSection (&handle_section);
+       InitializeCriticalSection (&allocator_section);
+
+#ifdef WITH_INCLUDED_LIBGC
+       gc_thread_vtable = &mono_gc_thread_vtable;
+#endif
 
 #ifdef ENABLE_FINALIZER_THREAD