[io-layer] Extract error (#4279)
[mono.git] / mono / metadata / gc.c
index 416d9350d457ee40de9d018536ac2beb28a8bd3b..9060cf400e012cdd756af2fa2de2b9ada65f71b3 100644 (file)
@@ -24,7 +24,7 @@
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/mono-mlist.h>
 #include <mono/metadata/threads-types.h>
-#include <mono/metadata/threadpool-ms.h>
+#include <mono/metadata/threadpool.h>
 #include <mono/sgen/sgen-conf.h>
 #include <mono/sgen/sgen-gc.h>
 #include <mono/utils/mono-logger-internals.h>
@@ -42,6 +42,7 @@
 #include <mono/utils/atomic.h>
 #include <mono/utils/mono-coop-semaphore.h>
 #include <mono/utils/hazard-pointer.h>
+#include <mono/utils/w32api.h>
 
 #ifndef HOST_WIN32
 #include <pthread.h>
@@ -494,14 +495,14 @@ mono_domain_finalize (MonoDomain *domain, guint32 timeout)
        mono_gc_finalize_notify ();
 
        if (timeout == -1)
-               timeout = INFINITE;
-       if (timeout != INFINITE)
+               timeout = MONO_INFINITE_WAIT;
+       if (timeout != MONO_INFINITE_WAIT)
                start = mono_msec_ticks ();
 
        ret = TRUE;
 
        for (;;) {
-               if (timeout == INFINITE) {
+               if (timeout == MONO_INFINITE_WAIT) {
                        res = mono_coop_sem_wait (&req->done, MONO_SEM_FLAGS_ALERTABLE);
                } else {
                        gint64 elapsed = mono_msec_ticks () - start;
@@ -556,7 +557,7 @@ mono_domain_finalize (MonoDomain *domain, guint32 timeout)
        }
 
        if (domain == mono_get_root_domain ()) {
-               mono_threadpool_ms_cleanup ();
+               mono_threadpool_cleanup ();
                mono_gc_finalize_threadpool_threads ();
        }
 
@@ -652,7 +653,7 @@ ves_icall_System_GC_WaitForPendingFinalizers (void)
        pending_done = FALSE;
        mono_gc_finalize_notify ();
        while (!pending_done) {
-               coop_cond_timedwait_alertable (&pending_done_cond, &pending_done_mutex, INFINITE, &alerted);
+               coop_cond_timedwait_alertable (&pending_done_cond, &pending_done_mutex, MONO_INFINITE_WAIT, &alerted);
                if (alerted)
                        break;
        }
@@ -732,7 +733,7 @@ ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle)
                } else {
                        /* the C# code will check and throw the exception */
                        /* FIXME: missing !klass->blittable test, see bug #61134 */
-                       if ((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_AUTO_LAYOUT)
+                       if (mono_class_is_auto_layout (klass))
                                return (gpointer)-1;
                        return (char*)obj + sizeof (MonoObject);
                }
@@ -882,7 +883,7 @@ finalize_domain_objects (void)
        }
 }
 
-static guint32
+static gsize WINAPI
 finalizer_thread (gpointer unused)
 {
        MonoError error;
@@ -1018,11 +1019,12 @@ mono_gc_cleanup (void)
                if (mono_thread_internal_current () != gc_thread) {
                        int ret;
                        gint64 start_ticks = mono_msec_ticks ();
-                       gint64 end_ticks = start_ticks + 2000;
+                       gint64 end_ticks = start_ticks + 40000;
 
                        mono_gc_finalize_notify ();
                        /* Finishing the finalizer thread, so wait a little bit... */
-                       /* MS seems to wait for about 2 seconds */
+                       /* MS seems to wait for about 2 seconds per finalizer thread */
+                       /* and 40 seconds for all finalizers to finish */
                        while (!finalizer_thread_exited) {
                                gint64 current_ticks = mono_msec_ticks ();
                                guint32 timeout;
@@ -1062,7 +1064,7 @@ mono_gc_cleanup (void)
 
 
                        /* Wait for the thread to actually exit */
-                       ret = guarded_wait (gc_thread->handle, INFINITE, TRUE);
+                       ret = guarded_wait (gc_thread->handle, MONO_INFINITE_WAIT, TRUE);
                        g_assert (ret == MONO_THREAD_INFO_WAIT_RET_SUCCESS_0);
 
                        mono_thread_join (GUINT_TO_POINTER (gc_thread->tid));