Cleanup the reference queue on domain unload.
[mono.git] / mono / metadata / attach.c
index ba611b381bef3c0da37d00a025a56c5cd7785f67..b14709aeabc85b89e7e42f4e39c9b2c6a0d01a89 100644 (file)
@@ -4,13 +4,13 @@
  * Author:
  *   Zoltan Varga (vargaz@gmail.com)
  *
- * (C) 2007-2008 Novell, Inc.
+ * Copyright 2007-2009 Novell, Inc (http://www.novell.com)
  */
 
 #include <config.h>
 #include <glib.h>
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
 #define DISABLE_ATTACH
 #endif
 #ifndef DISABLE_ATTACH
@@ -108,8 +108,6 @@ static guint32 WINAPI receiver_thread (void *arg);
 
 static void transport_start_receive (void);
 
-static void maybe_start (gpointer user_data);
-
 /*
  * Functions to decode protocol data
  */
@@ -185,8 +183,6 @@ decode_string_value (guint8 *buf, guint8 **endbuf, guint8 *limit)
 void
 mono_attach_parse_options (char *options)
 {
-       config.enabled = TRUE;
-
        if (!options)
                return;
        if (!strcmp (options, "disable"))
@@ -198,9 +194,7 @@ mono_attach_init (void)
 {
        InitializeCriticalSection (&agent_mutex);
 
-#ifndef HAVE_NULL_GC
-       mono_gc_add_finalizer_thread_callback (maybe_start, NULL);
-#endif
+       config.enabled = TRUE;
 }
 
 /**
@@ -244,15 +238,14 @@ mono_attach_start (void)
         * do the actual startup.
         */
        needs_to_start = TRUE;
-       // FIXME: This is not actually signal-safe
        mono_gc_finalize_notify ();
 
        return TRUE;
 }
 
 /* Called by the finalizer thread when it is woken up */
-static void
-maybe_start (gpointer user_data)
+void
+mono_attach_maybe_start (void)
 {
        if (!needs_to_start)
                return;
@@ -373,7 +366,12 @@ ipc_connect (void)
         */
        /* FIXME: Use TMP ? */
        pw = NULL;
+#ifdef HAVE_GETPWUID_R
        res = getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw);
+#else
+       pw = getpwuid(getuid ());
+       res = pw != NULL ? 0 : 1;
+#endif
        if (res != 0) {
                fprintf (stderr, "attach: getpwuid_r () failed.\n");
                return;
@@ -482,7 +480,7 @@ transport_start_receive (void)
        if (!listen_fd)
                return;
 
-       receiver_thread_handle = CreateThread (NULL, 0, receiver_thread, NULL, 0, &tid);
+       receiver_thread_handle = mono_create_thread (NULL, 0, receiver_thread, NULL, 0, &tid);
        g_assert (receiver_thread_handle);
 }
 
@@ -508,7 +506,7 @@ receiver_thread (void *arg)
                /* Ask the runtime to not abort this thread */
                //mono_thread_current ()->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
                /* Ask the runtime to not wait for this thread */
-               mono_thread_current ()->state |= ThreadState_Background;
+               mono_thread_internal_current ()->state |= ThreadState_Background;
 
                while (TRUE) {
                        char *cmd, *agent_name, *agent_args;
@@ -594,6 +592,11 @@ mono_attach_start (void)
        return FALSE;
 }
 
+void
+mono_attach_maybe_start (void)
+{
+}
+
 void
 mono_attach_cleanup (void)
 {