Merge pull request #615 from nealef/master
[mono.git] / mono / metadata / threadpool.c
index e8a2f1a45741b3248d33e1a1ed238c1d91c81d17..9a9e7a4cb345ac73cd88bce8d3ed4a273fd8d461 100644 (file)
@@ -29,6 +29,7 @@
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-proclib.h>
 #include <mono/utils/mono-semaphore.h>
+#include <mono/utils/atomic.h>
 #include <errno.h>
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
@@ -158,6 +159,7 @@ static MonoClass *process_async_call_klass;
 
 static GPtrArray *wsqs;
 CRITICAL_SECTION wsqs_lock;
+static gboolean suspended;
 
 /* Hooks */
 static MonoThreadPoolFunc tp_start_func;
@@ -777,6 +779,9 @@ monitor_thread (gpointer unused)
                if (mono_runtime_is_shutting_down ())
                        break;
 
+               if (suspended)
+                       continue;
+
                for (i = 0; i < 2; i++) {
                        ThreadPool *tp;
                        tp = pools [i];
@@ -1675,3 +1680,21 @@ mono_internal_thread_unhandled_exception (MonoObject* exc)
                 mono_thread_internal_reset_abort (mono_thread_internal_current ());
        }
 }
+
+/*
+ * Suspend creation of new threads.
+ */
+void
+mono_thread_pool_suspend (void)
+{
+       suspended = TRUE;
+}
+
+/*
+ * Resume creation of new threads.
+ */
+void
+mono_thread_pool_resume (void)
+{
+       suspended = FALSE;
+}