[threadpool] Fix `MonoTests.runtime.unload-appdomain-on-shutdown.exe` (#4135)
authorLudovic Henry <ludovic@xamarin.com>
Tue, 13 Dec 2016 21:53:03 +0000 (16:53 -0500)
committerGitHub <noreply@github.com>
Tue, 13 Dec 2016 21:53:03 +0000 (16:53 -0500)
* [threadpool] Increase and decrease refcount when removing domain

* [threadpool] Fix unload-appdomain-on-shutdown.exe

If the threadpool is not initialized, there is no need to initialize it, as no worker is going to start in the domain because mono_domain_is_unloading would return TRUE.

mono/metadata/threadpool.c

index ab88e67f4b960c6de4e6d2e52e3f38edd3cd7b29..9b404869ea436ca4de3ea43e0596c4aee45d0d2e 100644 (file)
@@ -607,12 +607,18 @@ mono_threadpool_remove_domain_jobs (MonoDomain *domain, int timeout)
         * The is_unloading () check in worker_request () ensures that
         * no new jobs are added after we enter the lock below.
         */
-       mono_lazy_initialize (&status, initialize);
+
+       if (!mono_lazy_is_initialized (&status))
+               return TRUE;
+
+       mono_refcount_inc (threadpool);
+
        domains_lock ();
 
        tpdomain = tpdomain_get (domain, FALSE);
        if (!tpdomain) {
                domains_unlock ();
+               mono_refcount_dec (threadpool);
                return TRUE;
        }
 
@@ -647,6 +653,8 @@ mono_threadpool_remove_domain_jobs (MonoDomain *domain, int timeout)
        mono_coop_cond_destroy (&tpdomain->cleanup_cond);
        tpdomain_free (tpdomain);
 
+       mono_refcount_dec (threadpool);
+
        return ret;
 }