2004-05-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mono / metadata / gc.c
index b548bfa3106ef7a2474b2c01830b3f6820589e69..cc1e2902a6970a8e937e589fece408b034506110 100644 (file)
@@ -88,6 +88,12 @@ run_finalize (void *obj, void *data)
 
        /* make sure the finalizer is not called again if the object is resurrected */
        object_register_finalizer (obj, NULL);
+
+       if (o->vtable->klass == mono_defaults.thread_class)
+               if (mono_gc_is_finalizer_thread ((MonoThread*)o))
+                       /* Avoid finalizing ourselves */
+                       return;
+
        /* speedup later... and use a timeout */
        /* g_print ("Finalize run on %p %s.%s\n", o, mono_object_class (o)->name_space, mono_object_class (o)->name); */
 
@@ -191,11 +197,14 @@ mono_domain_finalize (MonoDomain *domain, guint32 timeout)
 
        res = WaitForSingleObject (done_event, timeout);
 
-       //printf ("WAIT RES: %d.\n", res);
-       if (res == WAIT_TIMEOUT)
+       /* printf ("WAIT RES: %d.\n", res); */
+       if (res == WAIT_TIMEOUT) {
+               /* We leak the handle here */
                return FALSE;
-       else
-               return TRUE;
+       }
+
+       CloseHandle (done_event);
+       return TRUE;
 #else
        /* We don't support domain finalization without a GC */
        return FALSE;
@@ -501,17 +510,15 @@ finalize_domain_objects (DomainFinalizationReq *req)
                g_ptr_array_free (objs, TRUE);
        }
 
-       //printf ("DONE.\n");
+       /* printf ("DONE.\n"); */
        SetEvent (req->done_event);
 
-       /* FIXME: How to delete the event ? */
+       /* The event is closed in mono_domain_finalize if we get here */
        g_free (req);
 }
 
 static guint32 finalizer_thread (gpointer unused)
 {
-       guint32 stack_start;
-       
        gc_thread = mono_thread_current ();
 
        SetEvent (thread_started_event);
@@ -656,6 +663,26 @@ void mono_gc_cleanup (void)
 #endif
 }
 
+void
+mono_gc_disable (void)
+{
+#ifdef HAVE_GC_ENABLE
+       GC_disable ();
+#else
+       g_assert_not_reached ();
+#endif
+}
+
+void
+mono_gc_enable (void)
+{
+#ifdef HAVE_GC_ENABLE
+       GC_enable ();
+#else
+       g_assert_not_reached ();
+#endif
+}
+
 #else
 
 /* no Boehm GC support. */
@@ -668,6 +695,16 @@ void mono_gc_cleanup (void)
 {
 }
 
+void
+mono_gc_disable (void)
+{
+}
+
+void
+mono_gc_enable (void)
+{
+}
+
 #endif
 
 gboolean