ソースを参照

[threadpool] Remove mono threadpool implementation

Ludovic Henry 10 年 前
コミット
93bb234cea

+ 1 - 1
external/referencesource

@@ -1 +1 @@
-Subproject commit abe1cdfb1f941a03c477546534b33693a2ed1b40
+Subproject commit c92fc895c4575faf2e505c5a25c405cefffe10dc

+ 0 - 6
man/mono.1

@@ -1482,12 +1482,6 @@ include "clearlooks", "nice" and "win32".
 .Sp
 The default is "win32".  
 .TP
-\fBMONO_THREAPOOL\fR
-This environment variable can be used to choose the implementation of
-the ThreadPool used at runtime.  By default this uses the long term
-Mono threadpool implementation.   But a new "microsoft" value switches
-the threadpool implementation to Microsoft's CoreCLR/ReferenceSource implementation.
-.TP
 \fBMONO_TLS_SESSION_CACHE_TIMEOUT\fR
 The time, in seconds, that the SSL/TLS session cache will keep it's entry to
 avoid a new negotiation between the client and a server. Negotiation are very

+ 1 - 1
mcs/class/corlib/System.Threading/Timer.cs

@@ -347,7 +347,7 @@ namespace System.Threading
 							list.RemoveAt (i);
 							count--;
 							i--;
-							ThreadPool.QueueWorkItem (TimerCB, timer);
+							ThreadPool.UnsafeQueueUserWorkItem (TimerCB, timer);
 							long period = timer.period_ms;
 							long due_time = timer.due_time_ms;
 							bool no_more = (period == -1 || ((period == 0 || period == Timeout.Infinite) && due_time != Timeout.Infinite));

+ 0 - 1
mcs/class/corlib/corlib.dll.sources

@@ -874,7 +874,6 @@ System.Threading/Overlapped.cs
 System.Threading/ReaderWriterLock.cs
 System.Threading/RegisteredWaitHandle.cs
 System.Threading/Thread.cs
-System.Threading/ThreadPool.cs
 System.Threading/Timer.cs
 System.Threading/TimerCallback.cs
 System.Threading/Volatile.cs

+ 0 - 9
mono/metadata/Makefile.am

@@ -153,8 +153,6 @@ common_sources = \
 	mono-basic-block.c	\
 	mono-basic-block.h	\
 	mono-config.c		\
-	mono-cq.c		\
-	mono-cq.h		\
 	mono-debug.h		\
 	mono-debug.c		\
 	mono-debug-debugger.h	\
@@ -169,8 +167,6 @@ common_sources = \
 	mono-ptr-array.h	\
 	mono-route.c		\
 	mono-route.h		\
-	mono-wsq.c		\
-	mono-wsq.h		\
 	monitor.h		\
 	nacl-stub.c		\
 	normalization-tables.h	\
@@ -203,14 +199,10 @@ common_sources = \
 	tabledefs.h 		\
 	threads.c		\
 	threads-types.h		\
-	threadpool.c		\
-	threadpool.h		\
-	threadpool-internals.h	\
 	threadpool-ms.c	\
 	threadpool-ms.h	\
 	threadpool-ms-io.c	\
 	threadpool-ms-io.h	\
-	tpool-poll.c	\
 	verify.c		\
 	verify-internals.h	\
 	wrapper-types.h	\
@@ -328,5 +320,4 @@ endif
 endif
 
 EXTRA_DIST = $(win32_sources) $(unix_sources) $(null_sources) runtime.h \
-		tpool-poll.c tpool-epoll.c tpool-kqueue.c \
 		threadpool-ms-io-poll.c threadpool-ms-io-epoll.c threadpool-ms-io-kqueue.c

+ 2 - 3
mono/metadata/appdomain.c

@@ -39,13 +39,13 @@
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/threads.h>
+#include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/socket-io.h>
 #include <mono/metadata/tabledefs.h>
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/mono-gc.h>
 #include <mono/metadata/marshal.h>
 #include <mono/metadata/monitor.h>
-#include <mono/metadata/threadpool.h>
 #include <mono/metadata/mono-debug.h>
 #include <mono/metadata/mono-debug-debugger.h>
 #include <mono/metadata/attach.h>
@@ -232,7 +232,6 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
 	
 	mono_gc_base_init ();
 	mono_monitor_init ();
-	mono_thread_pool_init ();
 	mono_marshal_init ();
 
 	mono_install_assembly_preload_hook (mono_domain_assembly_preload, GUINT_TO_POINTER (FALSE));
@@ -2277,7 +2276,7 @@ unload_thread_main (void *arg)
 		goto failure;
 	}
 
-	if (!mono_thread_pool_remove_domain_jobs (domain, -1)) {
+	if (!mono_threadpool_ms_remove_domain_jobs (domain, -1)) {
 		data->failure_reason = g_strdup_printf ("Cleanup of threadpool jobs of domain %s timed out.", domain->friendly_name);
 		goto failure;
 	}

+ 0 - 1
mono/metadata/cominterop.c

@@ -23,7 +23,6 @@
 #include "metadata/appdomain.h"
 #include "metadata/reflection-internals.h"
 #include "mono/metadata/debug-helpers.h"
-#include "mono/metadata/threadpool.h"
 #include "mono/metadata/threads.h"
 #include "mono/metadata/monitor.h"
 #include "mono/metadata/metadata-internals.h"

+ 2 - 2
mono/metadata/console-unix.c

@@ -33,7 +33,7 @@
 #include <mono/metadata/domain-internals.h>
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/metadata.h>
-#include <mono/metadata/threadpool.h>
+#include <mono/metadata/threadpool-ms.h>
 #include <mono/utils/mono-signal-handler.h>
 #include <mono/utils/mono-proclib.h>
 
@@ -251,7 +251,7 @@ do_console_cancel_event (void)
 	method = mono_class_get_method_from_name (klass, "BeginInvoke", -1);
 	g_assert (method != NULL);
 
-	mono_thread_pool_begin_invoke (domain, (MonoObject*) load_value, method, NULL);
+	mono_threadpool_ms_begin_invoke (domain, (MonoObject*) load_value, method, NULL);
 }
 
 static int need_cancel = FALSE;

+ 0 - 1
mono/metadata/console-win32.c

@@ -26,7 +26,6 @@
 #include <mono/metadata/domain-internals.h>
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/metadata.h>
-#include <mono/metadata/threadpool.h>
 
 #include <mono/metadata/console-io.h>
 #include <mono/metadata/exception.h>

+ 3 - 4
mono/metadata/gc.c

@@ -22,9 +22,8 @@
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/mono-mlist.h>
-#include <mono/metadata/threadpool.h>
-#include <mono/metadata/threadpool-internals.h>
 #include <mono/metadata/threads-types.h>
+#include <mono/metadata/threadpool-ms.h>
 #include <mono/sgen/sgen-conf.h>
 #include <mono/utils/mono-logger-internal.h>
 #include <mono/metadata/gc-internal.h>
@@ -242,7 +241,7 @@ mono_gc_run_finalize (void *obj, void *data)
 		g_log ("mono-gc-finalizers", G_LOG_LEVEL_MESSAGE, "<%s at %p> Returned from finalizer.", o->vtable->klass->name, o);
 
 	if (exc)
-		mono_internal_thread_unhandled_exception (exc);
+		mono_thread_internal_unhandled_exception (exc);
 
 	mono_domain_set_internal (caller_domain);
 }
@@ -421,7 +420,7 @@ mono_domain_finalize (MonoDomain *domain, guint32 timeout)
 	CloseHandle (done_event);
 
 	if (domain == mono_get_root_domain ()) {
-		mono_thread_pool_cleanup ();
+		mono_threadpool_ms_cleanup ();
 		mono_gc_finalize_threadpool_threads ();
 	}
 

+ 13 - 21
mono/metadata/icall-def.h

@@ -862,21 +862,6 @@ ICALL(ILOCK_22, "Read(long&)", ves_icall_System_Threading_Interlocked_Read_Long)
 ICALL_TYPE(ITHREAD, "System.Threading.InternalThread", ITHREAD_1)
 ICALL(ITHREAD_1, "Thread_free_internal", ves_icall_System_Threading_InternalThread_Thread_free_internal)
 
-ICALL_TYPE(MTHREADP, "System.Threading.Microsoft.ThreadPool", MTHREADP_1)
-ICALL(MTHREADP_1, "BindIOCompletionCallbackNative", ves_icall_System_Threading_Microsoft_ThreadPool_BindIOCompletionCallbackNative)
-ICALL(MTHREADP_2, "GetAvailableThreadsNative", ves_icall_System_Threading_Microsoft_ThreadPool_GetAvailableThreadsNative)
-ICALL(MTHREADP_3, "GetMaxThreadsNative", ves_icall_System_Threading_Microsoft_ThreadPool_GetMaxThreadsNative)
-ICALL(MTHREADP_4, "GetMinThreadsNative", ves_icall_System_Threading_Microsoft_ThreadPool_GetMinThreadsNative)
-ICALL(MTHREADP_5, "InitializeVMTp", ves_icall_System_Threading_Microsoft_ThreadPool_InitializeVMTp)
-ICALL(MTHREADP_6, "IsThreadPoolHosted", ves_icall_System_Threading_Microsoft_ThreadPool_IsThreadPoolHosted)
-ICALL(MTHREADP_7, "NotifyWorkItemComplete", ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemComplete)
-ICALL(MTHREADP_8, "NotifyWorkItemProgressNative", ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemProgressNative)
-ICALL(MTHREADP_9, "PostQueuedCompletionStatus", ves_icall_System_Threading_Microsoft_ThreadPool_PostQueuedCompletionStatus)
-ICALL(MTHREADP_11, "ReportThreadStatus", ves_icall_System_Threading_Microsoft_ThreadPool_ReportThreadStatus)
-ICALL(MTHREADP_12, "RequestWorkerThread", ves_icall_System_Threading_Microsoft_ThreadPool_RequestWorkerThread)
-ICALL(MTHREADP_13, "SetMaxThreadsNative", ves_icall_System_Threading_Microsoft_ThreadPool_SetMaxThreadsNative)
-ICALL(MTHREADP_14, "SetMinThreadsNative", ves_icall_System_Threading_Microsoft_ThreadPool_SetMinThreadsNative)
-
 ICALL_TYPE(MONIT, "System.Threading.Monitor", MONIT_8)
 ICALL(MONIT_8, "Enter", mono_monitor_enter)
 ICALL(MONIT_1, "Exit", mono_monitor_exit)
@@ -960,12 +945,19 @@ ICALL(THREAD_9, "YieldInternal", ves_icall_System_Threading_Thread_Yield)
 ICALL(THREAD_52, "current_lcid()", ves_icall_System_Threading_Thread_current_lcid)
 
 ICALL_TYPE(THREADP, "System.Threading.ThreadPool", THREADP_1)
-ICALL(THREADP_1, "GetAvailableThreads_internal", ves_icall_System_Threading_ThreadPool_GetAvailableThreads)
-ICALL(THREADP_2, "GetMaxThreads_internal", ves_icall_System_Threading_ThreadPool_GetMaxThreads)
-ICALL(THREADP_3, "GetMinThreads_internal", ves_icall_System_Threading_ThreadPool_GetMinThreads)
-ICALL(THREADP_35, "SetMaxThreads_internal", ves_icall_System_Threading_ThreadPool_SetMaxThreads)
-ICALL(THREADP_4, "SetMinThreads_internal", ves_icall_System_Threading_ThreadPool_SetMinThreads)
-ICALL(THREADP_5, "pool_queue", icall_append_job)
+ICALL(THREADP_1, "BindIOCompletionCallbackNative", ves_icall_System_Threading_ThreadPool_BindIOCompletionCallbackNative)
+ICALL(THREADP_2, "GetAvailableThreadsNative", ves_icall_System_Threading_ThreadPool_GetAvailableThreadsNative)
+ICALL(THREADP_3, "GetMaxThreadsNative", ves_icall_System_Threading_ThreadPool_GetMaxThreadsNative)
+ICALL(THREADP_4, "GetMinThreadsNative", ves_icall_System_Threading_ThreadPool_GetMinThreadsNative)
+ICALL(THREADP_5, "InitializeVMTp", ves_icall_System_Threading_ThreadPool_InitializeVMTp)
+ICALL(THREADP_6, "IsThreadPoolHosted", ves_icall_System_Threading_ThreadPool_IsThreadPoolHosted)
+ICALL(THREADP_7, "NotifyWorkItemComplete", ves_icall_System_Threading_ThreadPool_NotifyWorkItemComplete)
+ICALL(THREADP_8, "NotifyWorkItemProgressNative", ves_icall_System_Threading_ThreadPool_NotifyWorkItemProgressNative)
+ICALL(THREADP_9, "PostQueuedCompletionStatus", ves_icall_System_Threading_ThreadPool_PostQueuedCompletionStatus)
+ICALL(THREADP_11, "ReportThreadStatus", ves_icall_System_Threading_ThreadPool_ReportThreadStatus)
+ICALL(THREADP_12, "RequestWorkerThread", ves_icall_System_Threading_ThreadPool_RequestWorkerThread)
+ICALL(THREADP_13, "SetMaxThreadsNative", ves_icall_System_Threading_ThreadPool_SetMaxThreadsNative)
+ICALL(THREADP_14, "SetMinThreadsNative", ves_icall_System_Threading_ThreadPool_SetMinThreadsNative)
 
 ICALL_TYPE(TTIMER, "System.Threading.Timer", TTIMER_1)
 ICALL(TTIMER_1, "GetTimeMonotonic", mono_100ns_ticks)

+ 0 - 1
mono/metadata/icall.c

@@ -37,7 +37,6 @@
 #include <mono/metadata/object.h>
 #include <mono/metadata/threads.h>
 #include <mono/metadata/threads-types.h>
-#include <mono/metadata/threadpool.h>
 #include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/threadpool-ms-io.h>
 #include <mono/metadata/monitor.h>

+ 3 - 3
mono/metadata/marshal.c

@@ -25,7 +25,6 @@
 #include "metadata/appdomain.h"
 #include "mono/metadata/abi-details.h"
 #include "mono/metadata/debug-helpers.h"
-#include "mono/metadata/threadpool.h"
 #include "mono/metadata/threads.h"
 #include "mono/metadata/monitor.h"
 #include "mono/metadata/metadata-internals.h"
@@ -38,6 +37,7 @@
 #include "mono/metadata/cominterop.h"
 #include "mono/metadata/remoting.h"
 #include "mono/metadata/reflection-internals.h"
+#include "mono/metadata/threadpool-ms.h"
 #include "mono/utils/mono-counters.h"
 #include "mono/utils/mono-tls.h"
 #include "mono/utils/mono-memory-model.h"
@@ -2108,7 +2108,7 @@ mono_delegate_begin_invoke (MonoDelegate *delegate, gpointer *params)
 		method = mono_get_delegate_invoke (klass);
 	g_assert (method);
 
-	return mono_thread_pool_begin_invoke (mono_domain_get (), (MonoObject*) delegate, method, params);
+	return mono_threadpool_ms_begin_invoke (mono_domain_get (), (MonoObject*) delegate, method, params);
 }
 
 #ifndef DISABLE_JIT
@@ -2823,7 +2823,7 @@ mono_delegate_end_invoke (MonoDelegate *delegate, gpointer *params)
 	} else
 #endif
 	{
-		res = mono_thread_pool_end_invoke (ares, &out_args, &exc);
+		res = mono_threadpool_ms_end_invoke (ares, &out_args, &exc);
 	}
 
 	if (exc) {

+ 0 - 253
mono/metadata/mono-cq.c

@@ -1,253 +0,0 @@
-/*
- * mono-cq.c: concurrent queue
- *
- * Authors:
- *   Gonzalo Paniagua Javier ([email protected])
- *
- * Copyright (c) 2011 Novell, Inc (http://www.novell.com)
- * Copyright 2011 Xamarin Inc
- */
-
-#include <mono/metadata/object.h>
-#include <mono/metadata/mono-cq.h>
-#include <mono/metadata/mono-mlist.h>
-#include <mono/utils/mono-memory-model.h>
-#include <mono/utils/atomic.h>
-
-#define CQ_DEBUG(...)
-//#define CQ_DEBUG(...) g_message(__VA_ARGS__)
-
-struct _MonoCQ {
-	MonoMList *head;
-	MonoMList *tail;
-	volatile gint32 count;
-};
-
-/* matches the System.MonoListItem object */
-struct _MonoMList {
-	MonoObject object;
-	MonoMList *next;
-	MonoObject *data;
-};
-
-/* matches the System.MonoCQItem object */
-struct _MonoCQItem {
-	MonoObject object;
-	MonoArray *array; // MonoObjects
-	MonoArray *array_state; // byte array
-	volatile gint32 first;
-	volatile gint32 last;
-};
-
-typedef struct _MonoCQItem MonoCQItem;
-#define CQ_ARRAY_SIZE	64
-
-static MonoVTable *monocq_item_vtable = NULL;
-
-static MonoCQItem *
-mono_cqitem_alloc (void)
-{
-	MonoCQItem *queue;
-	MonoDomain *domain = mono_get_root_domain ();
-
-	if (!monocq_item_vtable) {
-		MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoCQItem");
-		monocq_item_vtable = mono_class_vtable (domain, klass);
-		g_assert (monocq_item_vtable);
-	}
-	queue = (MonoCQItem *) mono_object_new_fast (monocq_item_vtable);
-	MONO_OBJECT_SETREF (queue, array, mono_array_new (domain, mono_defaults.object_class, CQ_ARRAY_SIZE));
-	MONO_OBJECT_SETREF (queue, array_state, mono_array_new (domain, mono_defaults.byte_class, CQ_ARRAY_SIZE));
-	return queue;
-}
-
-MonoCQ *
-mono_cq_create ()
-{
-	MonoCQ *cq;
-
-	cq = g_new0 (MonoCQ, 1);
-	MONO_GC_REGISTER_ROOT_SINGLE (cq->head);
-	MONO_GC_REGISTER_ROOT_SINGLE (cq->tail);
-	cq->head = mono_mlist_alloc ((MonoObject *) mono_cqitem_alloc ());
-	cq->tail = cq->head;
-	CQ_DEBUG ("Created %p", cq);
-	return cq;
-}
-
-void
-mono_cq_destroy (MonoCQ *cq)
-{
-	CQ_DEBUG ("Destroy %p", cq);
-	if (!cq)
-		return;
-
-	mono_gc_bzero_aligned (cq, sizeof (MonoCQ));
-	MONO_GC_UNREGISTER_ROOT (cq->tail);
-	MONO_GC_UNREGISTER_ROOT (cq->head);
-	g_free (cq);
-}
-
-gint32
-mono_cq_count (MonoCQ *cq)
-{
-	if (!cq)
-		return 0;
-
-	CQ_DEBUG ("Count %d", cq->count);
-	return cq->count;
-}
-
-static void
-mono_cq_add_node (MonoCQ *cq)
-{
-	MonoMList *n;
-	MonoMList *prev_tail;
-
-	CQ_DEBUG ("Adding node");
-	n = mono_mlist_alloc ((MonoObject *) mono_cqitem_alloc ());
-	prev_tail = cq->tail;
-	MONO_OBJECT_SETREF (prev_tail, next, n);
-
-	/* prev_tail->next must be visible before the new tail is */
-	STORE_STORE_FENCE;
-
-	cq->tail = n;
-}
-
-static gboolean
-mono_cqitem_try_enqueue (MonoCQ *cq, MonoObject *obj)
-{
-	MonoCQItem *queue;
-	MonoMList *tail;
-	gint32 pos;
-
-	tail = cq->tail;
-	queue = (MonoCQItem *) tail->data;
-	do {
-		pos = queue->last;
-		if (pos >= CQ_ARRAY_SIZE) {
-			CQ_DEBUG ("enqueue(): pos >= CQ_ARRAY_SIZE, %d >= %d", pos, CQ_ARRAY_SIZE);
-			return FALSE;
-		}
-
-		if (InterlockedCompareExchange (&queue->last, pos + 1, pos) == pos) {
-			mono_array_setref_fast (queue->array, pos, obj);
-			STORE_STORE_FENCE;
-			mono_array_set_fast (queue->array_state, char, pos, TRUE);
-			if ((pos + 1) == CQ_ARRAY_SIZE) {
-				CQ_DEBUG ("enqueue(): pos + 1 == CQ_ARRAY_SIZE, %d. Adding node.", CQ_ARRAY_SIZE);
-				mono_cq_add_node (cq);
-			}
-			return TRUE;
-		}
-	} while (TRUE);
-	g_assert_not_reached ();
-}
-
-void
-mono_cq_enqueue (MonoCQ *cq, MonoObject *obj)
-{
-	if (cq == NULL || obj == NULL)
-		return;
-
-	do {
-		if (mono_cqitem_try_enqueue (cq, obj)) {
-			CQ_DEBUG ("Queued one");
-			InterlockedIncrement (&cq->count);
-			break;
-		}
-		SleepEx (0, FALSE);
-	} while (TRUE);
-}
-
-static void
-mono_cq_remove_node (MonoCQ *cq)
-{
-	MonoMList *old_head;
-
-	CQ_DEBUG ("Removing node");
-	old_head = cq->head;
-	/* Not needed now that array_state is GC memory
-	MonoCQItem *queue;
-	int i;
-	gboolean retry;
-	queue = (MonoCQItem *) old_head->data;
-	do {
-		retry = FALSE;
-		for (i = 0; i < CQ_ARRAY_SIZE; i++) {
-			if (mono_array_get (queue->array_state, char, i) == TRUE) {
-				retry = TRUE;
-				break;
-			}
-		}
-		if (retry)
-			SleepEx (0, FALSE);
-	} while (retry);
-	 */
-	while (old_head->next == NULL)
-		SleepEx (0, FALSE);
-	cq->head = old_head->next;
-	
-	MONO_OBJECT_SETREF (old_head, next, NULL);
-	old_head = NULL;
-}
-
-static gboolean
-mono_cqitem_try_dequeue (MonoCQ *cq, MonoObject **obj)
-{
-	MonoCQItem *queue;
-	MonoMList *head;
-	gint32 pos;
-
-	head = cq->head;
-	queue = (MonoCQItem *) head->data;
-	do {
-		pos = queue->first;
-		if (pos >= queue->last || pos >= CQ_ARRAY_SIZE)
-			return FALSE;
-
-		if (InterlockedCompareExchange (&queue->first, pos + 1, pos) == pos) {
-			while (mono_array_get (queue->array_state, char, pos) == FALSE) {
-				SleepEx (0, FALSE);
-			}
-			LOAD_LOAD_FENCE;
-			*obj = mono_array_get (queue->array, MonoObject *, pos);
-
-			/*
-			Here don't need to fence since the only spot that reads it is the one above.
-			Additionally, the first store is superfluous, so it can happen OOO with the second.
-			*/
-			mono_array_set (queue->array, MonoObject *, pos, NULL);
-			mono_array_set (queue->array_state, char, pos, FALSE);
-			
-			/*
-			We should do a STORE_LOAD fence here to make sure subsequent loads see new state instead
-			of the above stores. We can safely ignore this as the only issue of seeing a stale value
-			is the thread yielding. Given how unfrequent this will be in practice, we better avoid the
-			very expensive STORE_LOAD fence.
-			*/
-			
-			if ((pos + 1) == CQ_ARRAY_SIZE) {
-				mono_cq_remove_node (cq);
-			}
-			return TRUE;
-		}
-	} while (TRUE);
-	g_assert_not_reached ();
-}
-
-gboolean
-mono_cq_dequeue (MonoCQ *cq, MonoObject **result)
-{
-	while (cq->count > 0) {
-		if (mono_cqitem_try_dequeue (cq, result)) {
-			CQ_DEBUG ("Dequeued one");
-			InterlockedDecrement (&cq->count);
-			return TRUE;
-		}
-		SleepEx (0, FALSE);
-	}
-	return FALSE;
-}
-

+ 0 - 22
mono/metadata/mono-cq.h

@@ -1,22 +0,0 @@
-#ifndef _MONO_CQ_H
-#define _MONO_CQ_H
-
-#include <config.h>
-#include <glib.h>
-#include <mono/metadata/object.h>
-#include <mono/metadata/gc-internal.h>
-
-G_BEGIN_DECLS
-
-typedef struct _MonoCQ MonoCQ;
-
-MonoCQ *mono_cq_create (void);
-void mono_cq_destroy (MonoCQ *cq);
-gint mono_cq_count (MonoCQ *cq);
-void mono_cq_enqueue (MonoCQ *cq, MonoObject *obj);
-gboolean mono_cq_dequeue (MonoCQ *cq, MonoObject **result);
-
-G_END_DECLS
-
-#endif
-

+ 0 - 230
mono/metadata/mono-wsq.c

@@ -1,230 +0,0 @@
-/*
- * mono-wsq.c: work-stealing queue
- *
- * Authors:
- *   Gonzalo Paniagua Javier ([email protected])
- *
- * Copyright (c) 2010 Novell, Inc (http://www.novell.com)
- * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
- */
-
-#include <string.h>
-#include <mono/metadata/object.h>
-#include <mono/metadata/mono-wsq.h>
-#include <mono/utils/mono-semaphore.h>
-#include <mono/utils/mono-tls.h>
-#include <mono/utils/atomic.h>
-
-#define INITIAL_LENGTH	32
-#define WSQ_DEBUG(...)
-//#define WSQ_DEBUG(...) g_message(__VA_ARGS__)
-
-struct _MonoWSQ {
-	volatile gint head;
-	volatile gint tail;
-	MonoArray *queue;
-	gint32 mask;
-	gint32 suspended;
-	MonoSemType lock;
-};
-
-#define NO_KEY ((guint32) -1)
-static MonoNativeTlsKey wsq_tlskey;
-static gboolean wsq_tlskey_inited = FALSE;
-
-void
-mono_wsq_init ()
-{
-	if (wsq_tlskey_inited)
-		return;
-
-	mono_native_tls_alloc (&wsq_tlskey, NULL);
-	wsq_tlskey_inited = TRUE;
-}
-
-void
-mono_wsq_cleanup ()
-{
-	if (!wsq_tlskey_inited)
-		return;
-	mono_native_tls_free (wsq_tlskey);
-	wsq_tlskey_inited = FALSE;
-}
-
-MonoWSQ *
-mono_wsq_create ()
-{
-	MonoWSQ *wsq;
-	MonoDomain *root;
-
-	if (!wsq_tlskey_inited)
-		return NULL;
-
-	wsq = g_new0 (MonoWSQ, 1);
-	wsq->mask = INITIAL_LENGTH - 1;
-	wsq->suspended = 0;
-	MONO_GC_REGISTER_ROOT_SINGLE (wsq->queue);
-	root = mono_get_root_domain ();
-	wsq->queue = mono_array_new_cached (root, mono_defaults.object_class, INITIAL_LENGTH);
-	MONO_SEM_INIT (&wsq->lock, 1);
-	if (!mono_native_tls_set_value (wsq_tlskey, wsq)) {
-		mono_wsq_destroy (wsq);
-		wsq = NULL;
-	}
-	return wsq;
-}
-
-gboolean
-mono_wsq_suspend (MonoWSQ *wsq)
-{
-	return InterlockedCompareExchange (&wsq->suspended, 1, 0) == 0;
-}
-
-void
-mono_wsq_destroy (MonoWSQ *wsq)
-{
-	if (wsq == NULL || wsq->queue == NULL)
-		return;
-
-	g_assert (mono_wsq_count (wsq) == 0);
-	MONO_GC_UNREGISTER_ROOT (wsq->queue);
-	MONO_SEM_DESTROY (&wsq->lock);
-	memset (wsq, 0, sizeof (MonoWSQ));
-	if (wsq_tlskey_inited && mono_native_tls_get_value (wsq_tlskey) == wsq)
-		mono_native_tls_set_value (wsq_tlskey, NULL);
-	g_free (wsq);
-}
-
-gint
-mono_wsq_count (MonoWSQ *wsq)
-{
-	if (!wsq)
-		return 0;
-	return ((wsq->tail - wsq->head) & wsq->mask);
-}
-
-gboolean
-mono_wsq_local_push (void *obj)
-{
-	int tail;
-	int head;
-	int count;
-	MonoWSQ *wsq;
-
-	if (obj == NULL || !wsq_tlskey_inited)
-		return FALSE;
-
-	wsq = (MonoWSQ *) mono_native_tls_get_value (wsq_tlskey);
-	if (wsq == NULL) {
-		WSQ_DEBUG ("local_push: no wsq\n");
-		return FALSE;
-	}
-
-	if (wsq->suspended) {
-		WSQ_DEBUG ("local_push: wsq suspended\n");
-		return FALSE;
-	}
-
-	tail = wsq->tail;
-	if (tail < wsq->head + wsq->mask) {
-		mono_array_setref (wsq->queue, tail & wsq->mask, (MonoObject *) obj);
-		wsq->tail = tail + 1;
-		WSQ_DEBUG ("local_push: OK %p %p\n", wsq, obj);
-		return TRUE;
-	}
-
-	MONO_SEM_WAIT (&wsq->lock);
-	head = wsq->head;
-	count = wsq->tail - wsq->head;
-	if (count >= wsq->mask) {
-		MonoArray *new_array;
-		int length;
-		int i;
-
-		length = mono_array_length (wsq->queue);
-		new_array = mono_array_new_cached (mono_get_root_domain (), mono_defaults.object_class, length * 2);
-		for (i = 0; i < length; i++)
-			mono_array_setref (new_array, i, mono_array_get (wsq->queue, MonoObject*, (i + head) & wsq->mask));
-
-		mono_gc_bzero_aligned (mono_array_addr (wsq->queue, MonoObject *, 0), sizeof (MonoObject*) * length);
-		wsq->queue = new_array;
-		wsq->head = 0;
-		wsq->tail = tail = count;
-		wsq->mask = (wsq->mask << 1) | 1;
-	}
-	mono_array_setref (wsq->queue, tail & wsq->mask, obj);
-	wsq->tail = tail + 1;
-	MONO_SEM_POST (&wsq->lock);
-	WSQ_DEBUG ("local_push: LOCK %p  %p\n", wsq, obj);
-	return TRUE;
-}
-
-gboolean
-mono_wsq_local_pop (void **ptr)
-{
-	int tail;
-	gboolean res;
-	MonoWSQ *wsq;
-
-	if (ptr == NULL || !wsq_tlskey_inited)
-		return FALSE;
-
-	wsq = (MonoWSQ *) mono_native_tls_get_value (wsq_tlskey);
-	if (wsq == NULL) {
-		WSQ_DEBUG ("local_pop: no wsq\n");
-		return FALSE;
-	}
-
-	tail = wsq->tail;
-	if (wsq->head >= tail) {
-		WSQ_DEBUG ("local_pop: empty\n");
-		return FALSE;
-	}
-	tail--;
-	InterlockedExchange (&wsq->tail, tail);
-	if (wsq->head <= tail) {
-		*ptr = mono_array_get (wsq->queue, void *, tail & wsq->mask);
-		mono_array_set (wsq->queue, void *, tail & wsq->mask, NULL);
-		WSQ_DEBUG ("local_pop: GOT ONE %p %p\n", wsq, *ptr);
-		return TRUE;
-	}
-
-	MONO_SEM_WAIT (&wsq->lock);
-	if (wsq->head <= tail) {
-		*ptr = mono_array_get (wsq->queue, void *, tail & wsq->mask);
-		mono_array_set (wsq->queue, void *, tail & wsq->mask, NULL);
-		res = TRUE;
-	} else {
-		wsq->tail = tail + 1;
-		res = FALSE;
-	}
-	MONO_SEM_POST (&wsq->lock);
-	WSQ_DEBUG ("local_pop: LOCK %d %p %p\n", res, wsq, *ptr);
-	return res;
-}
-
-void
-mono_wsq_try_steal (MonoWSQ *wsq, void **ptr, guint32 ms_timeout)
-{
-	if (wsq == NULL || ptr == NULL || *ptr != NULL || !wsq_tlskey_inited)
-		return;
-
-	if (mono_native_tls_get_value (wsq_tlskey) == wsq)
-		return;
-
-	if (mono_sem_timedwait (&wsq->lock, ms_timeout, FALSE) == 0) {
-		int head;
-
-		head = wsq->head;
-		InterlockedExchange (&wsq->head, head + 1);
-		if (head < wsq->tail) {
-			*ptr = mono_array_get (wsq->queue, void *, head & wsq->mask);
-			mono_array_set (wsq->queue, void *, head & wsq->mask, NULL);
-			WSQ_DEBUG ("STEAL %p %p\n", wsq, *ptr);
-		} else {
-			wsq->head = head;
-		}
-		MONO_SEM_POST (&wsq->lock);
-	}
-}
-

+ 0 - 27
mono/metadata/mono-wsq.h

@@ -1,27 +0,0 @@
-#ifndef _MONO_WSQ_H
-#define _MONO_WSQ_H
-
-#include <config.h>
-#include <glib.h>
-#include <mono/metadata/object.h>
-#include <mono/metadata/gc-internal.h>
-#include <mono/io-layer/io-layer.h>
-
-G_BEGIN_DECLS
-
-typedef struct _MonoWSQ MonoWSQ;
-
-void mono_wsq_init (void);
-void mono_wsq_cleanup (void);
-
-MonoWSQ *mono_wsq_create (void);
-void mono_wsq_destroy (MonoWSQ *wsq);
-gboolean mono_wsq_local_push (void *obj);
-gboolean mono_wsq_local_pop (void **ptr);
-void mono_wsq_try_steal (MonoWSQ *wsq, void **ptr, guint32 ms_timeout);
-gint mono_wsq_count (MonoWSQ *wsq);
-gboolean mono_wsq_suspend (MonoWSQ *wsq);
-
-G_END_DECLS
-
-#endif

+ 0 - 1
mono/metadata/object.c

@@ -27,7 +27,6 @@
 #include "mono/metadata/metadata-internals.h"
 #include "mono/metadata/class-internals.h"
 #include <mono/metadata/assembly.h>
-#include <mono/metadata/threadpool.h>
 #include <mono/metadata/marshal.h>
 #include "mono/metadata/debug-helpers.h"
 #include "mono/metadata/marshal.h"

+ 2 - 3
mono/metadata/runtime.c

@@ -17,7 +17,7 @@
 #include <mono/metadata/runtime.h>
 #include <mono/metadata/monitor.h>
 #include <mono/metadata/threads-types.h>
-#include <mono/metadata/threadpool.h>
+#include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/marshal.h>
 #include <mono/utils/atomic.h>
 
@@ -104,7 +104,7 @@ mono_runtime_try_shutdown (void)
 	mono_runtime_set_shutting_down ();
 
 	/* This will kill the tp threads which cannot be suspended */
-	mono_thread_pool_cleanup ();
+	mono_threadpool_ms_cleanup ();
 
 	/*TODO move the follow to here:
 	mono_thread_suspend_all_other_threads (); OR  mono_thread_wait_all_other_threads
@@ -132,6 +132,5 @@ void
 mono_runtime_init_tls (void)
 {
 	mono_marshal_init_tls ();
-	mono_thread_pool_init_tls ();
 	mono_thread_init_tls ();
 }

+ 2 - 2
mono/metadata/socket-io.c

@@ -53,10 +53,10 @@
 #include <mono/metadata/file-io.h>
 #include <mono/metadata/threads.h>
 #include <mono/metadata/threads-types.h>
+#include <mono/metadata/threadpool-ms-io.h>
 #include <mono/utils/mono-poll.h>
 /* FIXME change this code to not mess so much with the internals */
 #include <mono/metadata/class-internals.h>
-#include <mono/metadata/threadpool-internals.h>
 #include <mono/metadata/domain-internals.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-memory-model.h>
@@ -718,7 +718,7 @@ void ves_icall_System_Net_Sockets_Socket_Close_internal(SOCKET sock,
 
 	/* Clear any pending work item from this socket if the underlying
 	 * polling system does not notify when the socket is closed */
-	mono_thread_pool_remove_socket (GPOINTER_TO_INT (sock));
+	mono_threadpool_ms_io_remove_socket (GPOINTER_TO_INT (sock));
 	closesocket(sock);
 }
 

+ 0 - 34
mono/metadata/threadpool-internals.h

@@ -1,34 +0,0 @@
-#ifndef _MONO_THREADPOOL_INTERNALS_H_
-#define _MONO_THREADPOOL_INTERNALS_H_
-
-#include <glib.h>
-#include <mono/metadata/object.h>
-#include <mono/metadata/mono-hash.h>
-#include <mono/metadata/mono-mlist.h>
-#include <mono/utils/mono-compiler.h>
-#include <mono/utils/mono-mutex.h>
-
-typedef struct {
-	mono_mutex_t io_lock; /* access to sock_to_state */
-	int inited; // 0 -> not initialized , 1->initializing, 2->initialized, 3->cleaned up
-	MonoGHashTable *sock_to_state;
-
-	gint event_system;
-	gpointer event_data;
-	void (*modify) (gpointer p, int fd, int operation, int events, gboolean is_new);
-	void (*wait) (gpointer sock_data);
-	void (*shutdown) (gpointer event_data);
-} SocketIOData;
-
-void mono_thread_pool_remove_socket (int sock);
-gboolean mono_thread_pool_is_queue_array (MonoArray *o);
-void mono_internal_thread_unhandled_exception (MonoObject* exc);
-
-//TP internals the impls use
-void check_for_interruption_critical (void);
-void socket_io_cleanup (SocketIOData *data);
-MonoObject *get_io_event (MonoMList **list, gint event);
-int get_events_from_list (MonoMList *list);
-void threadpool_append_async_io_jobs (MonoObject **jobs, gint njobs);
-
-#endif

+ 1 - 1
mono/metadata/threadpool-ms-io-epoll.c

@@ -78,7 +78,7 @@ epoll_event_wait (void)
 	if (ready == -1) {
 		switch (errno) {
 		case EINTR:
-			check_for_interruption_critical ();
+			mono_thread_internal_check_for_interruption_critical (mono_thread_internal_current ());
 			ready = 0;
 			break;
 		default:

+ 1 - 1
mono/metadata/threadpool-ms-io-kqueue.c

@@ -68,7 +68,7 @@ kqueue_event_wait (void)
 	if (ready == -1) {
 		switch (errno) {
 		case EINTR:
-			check_for_interruption_critical ();
+			mono_thread_internal_check_for_interruption_critical (mono_thread_internal_current ());
 			ready = 0;
 			break;
 		default:

+ 1 - 1
mono/metadata/threadpool-ms-io-poll.c

@@ -133,7 +133,7 @@ poll_event_wait (void)
 #else
 		case WSAEINTR:
 #endif
-			check_for_interruption_critical ();
+			mono_thread_internal_check_for_interruption_critical (mono_thread_internal_current ());
 			ready = 0;
 			break;
 #if !defined(HOST_WIN32)

+ 20 - 1
mono/metadata/threadpool-ms-io.c

@@ -22,7 +22,6 @@
 
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/mono-mlist.h>
-#include <mono/metadata/threadpool-internals.h>
 #include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/threadpool-ms-io.h>
 #include <mono/utils/atomic.h>
@@ -659,6 +658,20 @@ mono_threadpool_ms_io_remove_domain_jobs (MonoDomain *domain)
 	mono_mutex_unlock (&threadpool_io->states_lock);
 }
 
+void
+icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state)
+{
+	MonoAsyncResult *ares;
+
+	/* Don't call mono_async_result_new() to avoid capturing the context */
+	ares = (MonoAsyncResult *) mono_object_new (mono_domain_get (), mono_defaults.asyncresult_class);
+	MONO_OBJECT_SETREF (ares, async_delegate, target);
+	MONO_OBJECT_SETREF (ares, async_state, state);
+
+	mono_threadpool_ms_io_add (ares, state);
+	return;
+}
+
 #else
 
 gboolean
@@ -691,4 +704,10 @@ mono_threadpool_ms_io_remove_domain_jobs (MonoDomain *domain)
 	g_assert_not_reached ();
 }
 
+void
+icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state)
+{
+	g_assert_not_reached ();
+}
+
 #endif

+ 3 - 0
mono/metadata/threadpool-ms-io.h

@@ -19,4 +19,7 @@ mono_threadpool_ms_io_remove_domain_jobs (MonoDomain *domain);
 void
 mono_threadpool_ms_io_cleanup (void);
 
+void
+icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state);
+
 #endif /* _MONO_THREADPOOL_MS_IO_H_ */

+ 15 - 16
mono/metadata/threadpool-ms.c

@@ -32,7 +32,6 @@
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/threadpool-ms-io.h>
-#include <mono/metadata/threadpool-internals.h>
 #include <mono/utils/atomic.h>
 #include <mono/utils/mono-compiler.h>
 #include <mono/utils/mono-complex.h>
@@ -583,7 +582,7 @@ worker_thread (gpointer data)
 	g_assert (status >= STATUS_INITIALIZED);
 
 	if (!threadpool_wait_callback_class)
-		threadpool_wait_callback_class = mono_class_from_name (mono_defaults.corlib, "System.Threading.Microsoft", "_ThreadPoolWaitCallback");
+		threadpool_wait_callback_class = mono_class_from_name (mono_defaults.corlib, "System.Threading", "_ThreadPoolWaitCallback");
 	g_assert (threadpool_wait_callback_class);
 
 	if (!perform_wait_callback_method)
@@ -649,7 +648,7 @@ worker_thread (gpointer data)
 			MonoObject *exc = NULL;
 			MonoObject *res = mono_runtime_invoke (perform_wait_callback_method, NULL, NULL, &exc);
 			if (exc)
-				mono_internal_thread_unhandled_exception (exc);
+				mono_thread_internal_unhandled_exception (exc);
 			else if (res && *(MonoBoolean*) mono_object_unbox (res) == FALSE)
 				retire = TRUE;
 
@@ -1379,7 +1378,7 @@ mono_threadpool_ms_resume (void)
 }
 
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_GetAvailableThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads)
+ves_icall_System_Threading_ThreadPool_GetAvailableThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads)
 {
 	if (!worker_threads || !completion_port_threads)
 		return;
@@ -1391,7 +1390,7 @@ ves_icall_System_Threading_Microsoft_ThreadPool_GetAvailableThreadsNative (gint3
 }
 
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_GetMinThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads)
+ves_icall_System_Threading_ThreadPool_GetMinThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads)
 {
 	if (!worker_threads || !completion_port_threads)
 		return;
@@ -1403,7 +1402,7 @@ ves_icall_System_Threading_Microsoft_ThreadPool_GetMinThreadsNative (gint32 *wor
 }
 
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_GetMaxThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads)
+ves_icall_System_Threading_ThreadPool_GetMaxThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads)
 {
 	if (!worker_threads || !completion_port_threads)
 		return;
@@ -1415,7 +1414,7 @@ ves_icall_System_Threading_Microsoft_ThreadPool_GetMaxThreadsNative (gint32 *wor
 }
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_SetMinThreadsNative (gint32 worker_threads, gint32 completion_port_threads)
+ves_icall_System_Threading_ThreadPool_SetMinThreadsNative (gint32 worker_threads, gint32 completion_port_threads)
 {
 	ensure_initialized (NULL);
 
@@ -1431,7 +1430,7 @@ ves_icall_System_Threading_Microsoft_ThreadPool_SetMinThreadsNative (gint32 work
 }
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_SetMaxThreadsNative (gint32 worker_threads, gint32 completion_port_threads)
+ves_icall_System_Threading_ThreadPool_SetMaxThreadsNative (gint32 worker_threads, gint32 completion_port_threads)
 {
 	gint cpu_count = mono_cpu_count ();
 
@@ -1449,13 +1448,13 @@ ves_icall_System_Threading_Microsoft_ThreadPool_SetMaxThreadsNative (gint32 work
 }
 
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_InitializeVMTp (MonoBoolean *enable_worker_tracking)
+ves_icall_System_Threading_ThreadPool_InitializeVMTp (MonoBoolean *enable_worker_tracking)
 {
 	ensure_initialized (enable_worker_tracking);
 }
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemComplete (void)
+ves_icall_System_Threading_ThreadPool_NotifyWorkItemComplete (void)
 {
 	ThreadPoolCounter counter;
 
@@ -1472,7 +1471,7 @@ ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemComplete (void)
 }
 
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemProgressNative (void)
+ves_icall_System_Threading_ThreadPool_NotifyWorkItemProgressNative (void)
 {
 	heuristic_notify_work_completed ();
 
@@ -1481,20 +1480,20 @@ ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemProgressNative (vo
 }
 
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_ReportThreadStatus (MonoBoolean is_working)
+ves_icall_System_Threading_ThreadPool_ReportThreadStatus (MonoBoolean is_working)
 {
 	// TODO
 	mono_raise_exception (mono_get_exception_not_implemented (NULL));
 }
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_RequestWorkerThread (void)
+ves_icall_System_Threading_ThreadPool_RequestWorkerThread (void)
 {
 	return worker_request (mono_domain_get ());
 }
 
 MonoBoolean G_GNUC_UNUSED
-ves_icall_System_Threading_Microsoft_ThreadPool_PostQueuedCompletionStatus (MonoNativeOverlapped *native_overlapped)
+ves_icall_System_Threading_ThreadPool_PostQueuedCompletionStatus (MonoNativeOverlapped *native_overlapped)
 {
 	/* This copy the behavior of the current Mono implementation */
 	mono_raise_exception (mono_get_exception_not_implemented (NULL));
@@ -1502,14 +1501,14 @@ ves_icall_System_Threading_Microsoft_ThreadPool_PostQueuedCompletionStatus (Mono
 }
 
 MonoBoolean G_GNUC_UNUSED
-ves_icall_System_Threading_Microsoft_ThreadPool_BindIOCompletionCallbackNative (gpointer file_handle)
+ves_icall_System_Threading_ThreadPool_BindIOCompletionCallbackNative (gpointer file_handle)
 {
 	/* This copy the behavior of the current Mono implementation */
 	return TRUE;
 }
 
 MonoBoolean G_GNUC_UNUSED
-ves_icall_System_Threading_Microsoft_ThreadPool_IsThreadPoolHosted (void)
+ves_icall_System_Threading_ThreadPool_IsThreadPoolHosted (void)
 {
 	return FALSE;
 }

+ 14 - 32
mono/metadata/threadpool-ms.h

@@ -5,6 +5,7 @@
 #include <glib.h>
 
 #include <mono/metadata/exception.h>
+#include <mono/metadata/object-internals.h>
 
 #define SMALL_STACK (sizeof (gpointer) * 32 * 1024)
 
@@ -18,18 +19,6 @@ enum {
 
 typedef struct _MonoNativeOverlapped MonoNativeOverlapped;
 
-static void G_GNUC_UNUSED
-mono_threadpool_ms_init (void)
-{
-	/* Initialization is done lazily */
-}
-
-static void G_GNUC_UNUSED
-mono_threadpool_ms_init_tls (void)
-{
-	/* The WSQ is now implemented in managed */
-}
-
 void
 mono_threadpool_ms_cleanup (void);
 
@@ -46,42 +35,35 @@ mono_threadpool_ms_suspend (void);
 void
 mono_threadpool_ms_resume (void);
 
-static gboolean G_GNUC_UNUSED
-mono_threadpool_ms_is_queue_array (MonoArray *arr)
-{
-	/* The queue is in managed code */
-	return FALSE;
-}
-
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_GetAvailableThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads);
+ves_icall_System_Threading_ThreadPool_GetAvailableThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads);
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_GetMinThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads);
+ves_icall_System_Threading_ThreadPool_GetMinThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads);
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_GetMaxThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads);
+ves_icall_System_Threading_ThreadPool_GetMaxThreadsNative (gint32 *worker_threads, gint32 *completion_port_threads);
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_SetMinThreadsNative (gint32 worker_threads, gint32 completion_port_threads);
+ves_icall_System_Threading_ThreadPool_SetMinThreadsNative (gint32 worker_threads, gint32 completion_port_threads);
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_SetMaxThreadsNative (gint32 worker_threads, gint32 completion_port_threads);
+ves_icall_System_Threading_ThreadPool_SetMaxThreadsNative (gint32 worker_threads, gint32 completion_port_threads);
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_InitializeVMTp (MonoBoolean *enable_worker_tracking);
+ves_icall_System_Threading_ThreadPool_InitializeVMTp (MonoBoolean *enable_worker_tracking);
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemComplete (void);
+ves_icall_System_Threading_ThreadPool_NotifyWorkItemComplete (void);
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_NotifyWorkItemProgressNative (void);
+ves_icall_System_Threading_ThreadPool_NotifyWorkItemProgressNative (void);
 void
-ves_icall_System_Threading_Microsoft_ThreadPool_ReportThreadStatus (MonoBoolean is_working);
+ves_icall_System_Threading_ThreadPool_ReportThreadStatus (MonoBoolean is_working);
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_RequestWorkerThread (void);
+ves_icall_System_Threading_ThreadPool_RequestWorkerThread (void);
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_PostQueuedCompletionStatus (MonoNativeOverlapped *native_overlapped);
+ves_icall_System_Threading_ThreadPool_PostQueuedCompletionStatus (MonoNativeOverlapped *native_overlapped);
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_BindIOCompletionCallbackNative (gpointer file_handle);
+ves_icall_System_Threading_ThreadPool_BindIOCompletionCallbackNative (gpointer file_handle);
 
 MonoBoolean
-ves_icall_System_Threading_Microsoft_ThreadPool_IsThreadPoolHosted (void);
+ves_icall_System_Threading_ThreadPool_IsThreadPoolHosted (void);
 
 /* Internals */
 

+ 0 - 1864
mono/metadata/threadpool.c

@@ -1,1864 +0,0 @@
-/*
- * threadpool.c: global thread pool
- *
- * Authors:
- *   Dietmar Maurer ([email protected])
- *   Gonzalo Paniagua Javier ([email protected])
- *
- * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
- * Copyright 2004-2010 Novell, Inc (http://www.novell.com)
- * Copyright 2001 Xamarin Inc (http://www.xamarin.com)
- */
-
-#include <config.h>
-#include <glib.h>
-
-#include <mono/metadata/profiler-private.h>
-#include <mono/metadata/threads.h>
-#include <mono/metadata/threads-types.h>
-#include <mono/metadata/threadpool-internals.h>
-#include <mono/metadata/exception.h>
-#include <mono/metadata/environment.h>
-#include <mono/metadata/mono-config.h>
-#include <mono/metadata/mono-mlist.h>
-#include <mono/metadata/mono-perfcounters.h>
-#include <mono/metadata/socket-io.h>
-#include <mono/metadata/mono-cq.h>
-#include <mono/metadata/mono-wsq.h>
-#include <mono/metadata/mono-ptr-array.h>
-#include <mono/metadata/object-internals.h>
-#include <mono/io-layer/io-layer.h>
-#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>
-#endif
-#include <sys/types.h>
-#include <fcntl.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <math.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#include <mono/utils/mono-poll.h>
-#ifdef HAVE_EPOLL
-#include <sys/epoll.h>
-#endif
-#ifdef HAVE_KQUEUE
-#include <sys/event.h>
-#endif
-
-
-#ifndef DISABLE_SOCKETS
-#include "mono/io-layer/socket-wrappers.h"
-#endif
-
-#include "threadpool.h"
-#include "threadpool-ms.h"
-#include "threadpool-ms-io.h"
-
-static gboolean
-use_ms_threadpool (void)
-{
-	static gboolean use_ms_tp = -1;
-	const gchar *mono_threadpool_env;
-	if (use_ms_tp != -1)
-		return use_ms_tp;
-	else if (!(mono_threadpool_env = g_getenv ("MONO_THREADPOOL")))
-		return use_ms_tp = FALSE;
-	else if (strcmp (mono_threadpool_env, "microsoft") == 0)
-		return use_ms_tp = TRUE;
-	else
-		return use_ms_tp = FALSE;
-}
-
-#define THREAD_WANTS_A_BREAK(t) ((t->state & (ThreadState_StopRequested | \
-						ThreadState_SuspendRequested)) != 0)
-
-/* DEBUG: prints tp data every 2s */
-#undef DEBUG 
-
-/* mono_thread_pool_init called */
-static volatile int tp_inited;
-
-enum {
-	POLL_BACKEND,
-	EPOLL_BACKEND,
-	KQUEUE_BACKEND
-};
-
-enum {
-	MONITOR_STATE_AWAKE,
-	MONITOR_STATE_FALLING_ASLEEP,
-	MONITOR_STATE_SLEEPING
-};
-
-static SocketIOData socket_io_data;
-
-typedef struct {
-	MonoSemType lock;
-	MonoCQ *queue; /* GC root */
-	MonoSemType new_job;
-	volatile gint waiting; /* threads waiting for a work item */
-
-	/**/
-	volatile gint pool_status; /* 0 -> not initialized, 1 -> initialized, 2 -> cleaning up */
-	/* min, max, n and busy -> Interlocked */
-	volatile gint min_threads;
-	volatile gint max_threads;
-	volatile gint nthreads;
-	volatile gint busy_threads;
-
-	void (*async_invoke) (gpointer data);
-	void *pc_nitems; /* Performance counter for total number of items in added */
-	void *pc_nthreads; /* Performance counter for total number of active threads */
-	/**/
-	volatile gint destroy_thread;
-#if DEBUG
-	volatile gint32 njobs;
-#endif
-	volatile gint32 nexecuted;
-	gboolean is_io;
-} ThreadPool;
-
-static ThreadPool async_tp;
-static ThreadPool async_io_tp;
-
-static void async_invoke_thread (gpointer data);
-static MonoObject *mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares);
-static void threadpool_free_queue (ThreadPool *tp);
-static void threadpool_append_job (ThreadPool *tp, MonoObject *ar);
-static void threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs);
-static void threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_invoke) (gpointer));
-static void threadpool_start_idle_threads (ThreadPool *tp);
-static void threadpool_kill_idle_threads (ThreadPool *tp);
-static gboolean threadpool_start_thread (ThreadPool *tp);
-static void threadpool_kill_thread (ThreadPool *tp);
-static void monitor_thread (gpointer data);
-static int get_event_from_state (MonoSocketAsyncResult *state);
-
-static MonoClass *async_call_klass;
-static MonoClass *socket_async_call_klass;
-static MonoClass *process_async_call_klass;
-
-static GPtrArray *threads;
-mono_mutex_t threads_lock;
-static GPtrArray *wsqs;
-mono_mutex_t wsqs_lock;
-static gboolean suspended;
-
-static volatile gint32 monitor_njobs = 0;
-static volatile gint32 monitor_state;
-static MonoSemType monitor_sem;
-static MonoInternalThread *monitor_internal_thread;
-
-/* Hooks */
-static MonoThreadPoolFunc tp_start_func;
-static MonoThreadPoolFunc tp_finish_func;
-static gpointer tp_hooks_user_data;
-static MonoThreadPoolItemFunc tp_item_begin_func;
-static MonoThreadPoolItemFunc tp_item_end_func;
-static gpointer tp_item_user_data;
-
-enum {
-	AIO_OP_FIRST,
-	AIO_OP_ACCEPT = 0,
-	AIO_OP_CONNECT,
-	AIO_OP_RECEIVE,
-	AIO_OP_RECEIVEFROM,
-	AIO_OP_SEND,
-	AIO_OP_SENDTO,
-	AIO_OP_RECV_JUST_CALLBACK,
-	AIO_OP_SEND_JUST_CALLBACK,
-	AIO_OP_READPIPE,
-	AIO_OP_CONSOLE2,
-	AIO_OP_DISCONNECT,
-	AIO_OP_ACCEPTRECEIVE,
-	AIO_OP_RECEIVE_BUFFERS,
-	AIO_OP_SEND_BUFFERS,
-	AIO_OP_LAST
-};
-
-// #include <mono/metadata/tpool-poll.c>
-gpointer tp_poll_init (SocketIOData *data);
-
-#ifdef HAVE_EPOLL
-#include <mono/metadata/tpool-epoll.c>
-#elif defined(USE_KQUEUE_FOR_THREADPOOL)
-#include <mono/metadata/tpool-kqueue.c>
-#endif
-/*
- * Functions to check whenever a class is given system class. We need to cache things in MonoDomain since some of the
- * assemblies can be unloaded.
- */
-
-static gboolean
-is_system_type (MonoDomain *domain, MonoClass *klass)
-{
-	if (domain->system_image == NULL)
-		domain->system_image = mono_image_loaded ("System");
-
-	return klass->image == domain->system_image;
-}
-
-static gboolean
-is_corlib_type (MonoDomain *domain, MonoClass *klass)
-{
-	return klass->image == mono_defaults.corlib;
-}
-
-#define check_type_cached(domain, ASSEMBLY, _class, _namespace, _name, loc) do { \
-	if (*loc) \
-		return *loc == _class; \
-	if (is_##ASSEMBLY##_type (domain, _class) && !strcmp (_name, _class->name) && !strcmp (_namespace, _class->name_space)) { \
-		*loc = _class; \
-		return TRUE; \
-	} \
-	return FALSE; \
-} while (0) \
-
-#define check_corlib_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, corlib, _class, _namespace, _name, loc)
-
-#define check_system_type_cached(domain, _class, _namespace, _name, loc) check_type_cached (domain, system, _class, _namespace, _name, loc)
-
-static gboolean
-is_corlib_asyncresult (MonoDomain *domain, MonoClass *klass)
-{
-	check_corlib_type_cached (domain, klass, "System.Runtime.Remoting.Messaging", "AsyncResult", &domain->corlib_asyncresult_class);
-}
-
-static gboolean
-is_socketasyncresult (MonoDomain *domain, MonoClass *klass)
-{
-	static MonoClass *socket_async_result_klass = NULL;
-	check_system_type_cached (domain, klass, "System.Net.Sockets", "SocketAsyncResult", &socket_async_result_klass);
-}
-
-static gboolean
-is_socketasynccall (MonoDomain *domain, MonoClass *klass)
-{
-	static MonoClass *socket_async_callback_klass = NULL;
-	check_system_type_cached (domain, klass, "System.Net.Sockets", "SocketAsyncCallback", &socket_async_callback_klass);
-}
-
-static gboolean
-is_appdomainunloaded_exception (MonoDomain *domain, MonoClass *klass)
-{
-	check_corlib_type_cached (domain, klass, "System", "AppDomainUnloadedException", &domain->ad_unloaded_ex_class);
-}
-
-static gboolean
-is_sd_process (MonoDomain *domain, MonoClass *klass)
-{
-	check_system_type_cached (domain, klass, "System.Diagnostics", "Process", &domain->process_class);
-}
-
-static gboolean
-is_sdp_asyncreadhandler (MonoDomain *domain, MonoClass *klass)
-{
-
-	return (klass->nested_in &&
-			is_sd_process (domain, klass->nested_in) &&
-		!strcmp (klass->name, "AsyncReadHandler"));
-}
-
-
-#ifdef DISABLE_SOCKETS
-
-void
-socket_io_cleanup (SocketIOData *data)
-{
-}
-
-static int
-get_event_from_state (MonoSocketAsyncResult *state)
-{
-	g_assert_not_reached ();
-	return -1;
-}
-
-int
-get_events_from_list (MonoMList *list)
-{
-	return 0;
-}
-
-#else
-
-void
-socket_io_cleanup (SocketIOData *data)
-{
-	mono_mutex_lock (&data->io_lock);
-	if (data->inited != 2) {
-		mono_mutex_unlock (&data->io_lock);
-		return;
-	}
-	data->inited = 3;
-	data->shutdown (data->event_data);
-	mono_mutex_unlock (&data->io_lock);
-}
-
-static int
-get_event_from_state (MonoSocketAsyncResult *state)
-{
-	switch (state->operation) {
-	case AIO_OP_ACCEPT:
-	case AIO_OP_RECEIVE:
-	case AIO_OP_RECV_JUST_CALLBACK:
-	case AIO_OP_RECEIVEFROM:
-	case AIO_OP_READPIPE:
-	case AIO_OP_ACCEPTRECEIVE:
-	case AIO_OP_RECEIVE_BUFFERS:
-		return MONO_POLLIN;
-	case AIO_OP_SEND:
-	case AIO_OP_SEND_JUST_CALLBACK:
-	case AIO_OP_SENDTO:
-	case AIO_OP_CONNECT:
-	case AIO_OP_SEND_BUFFERS:
-	case AIO_OP_DISCONNECT:
-		return MONO_POLLOUT;
-	default: /* Should never happen */
-		g_message ("get_event_from_state: unknown value in switch!!!");
-		return 0;
-	}
-}
-
-int
-get_events_from_list (MonoMList *list)
-{
-	MonoSocketAsyncResult *state;
-	int events = 0;
-
-	while (list && (state = (MonoSocketAsyncResult *)mono_mlist_get_data (list))) {
-		events |= get_event_from_state (state);
-		list = mono_mlist_next (list);
-	}
-
-	return events;
-}
-
-#endif /* !DISABLE_SOCKETS */
-
-static void
-threadpool_jobs_inc (MonoObject *obj)
-{
-	if (obj)
-		InterlockedIncrement (&obj->vtable->domain->threadpool_jobs);
-}
-
-static gboolean
-threadpool_jobs_dec (MonoObject *obj)
-{
-	MonoDomain *domain;
-	int remaining_jobs;
-
-	if (obj == NULL)
-		return FALSE;
-
-	domain = obj->vtable->domain;
-	remaining_jobs = InterlockedDecrement (&domain->threadpool_jobs);
-	if (remaining_jobs == 0 && domain->cleanup_semaphore) {
-		ReleaseSemaphore (domain->cleanup_semaphore, 1, NULL);
-		return TRUE;
-	}
-	return FALSE;
-}
-
-MonoObject *
-get_io_event (MonoMList **list, gint event)
-{
-	MonoObject *state;
-	MonoMList *current;
-	MonoMList *prev;
-
-	current = *list;
-	prev = NULL;
-	state = NULL;
-	while (current) {
-		state = mono_mlist_get_data (current);
-		if (get_event_from_state ((MonoSocketAsyncResult *) state) == event)
-			break;
-
-		state = NULL;
-		prev = current;
-		current = mono_mlist_next (current);
-	}
-
-	if (current) {
-		if (prev) {
-			mono_mlist_set_next (prev, mono_mlist_next (current));
-		} else {
-			*list = mono_mlist_next (*list);
-		}
-	}
-
-	return state;
-}
-
-/*
- * select/poll wake up when a socket is closed, but epoll just removes
- * the socket from its internal list without notification.
- */
-void
-mono_thread_pool_remove_socket (int sock)
-{
-	MonoMList *list;
-	MonoSocketAsyncResult *state;
-	MonoObject *ares;
-
-	if (use_ms_threadpool ()) {
-#ifndef DISABLE_SOCKETS
-		mono_threadpool_ms_io_remove_socket (sock);
-#endif
-		return;
-	}
-
-	if (socket_io_data.inited == 0)
-		return;
-
-	mono_mutex_lock (&socket_io_data.io_lock);
-	if (socket_io_data.sock_to_state == NULL) {
-		mono_mutex_unlock (&socket_io_data.io_lock);
-		return;
-	}
-	list = mono_g_hash_table_lookup (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
-	if (list)
-		mono_g_hash_table_remove (socket_io_data.sock_to_state, GINT_TO_POINTER (sock));
-	mono_mutex_unlock (&socket_io_data.io_lock);
-	
-	while (list) {
-		state = (MonoSocketAsyncResult *) mono_mlist_get_data (list);
-		if (state->operation == AIO_OP_RECEIVE)
-			state->operation = AIO_OP_RECV_JUST_CALLBACK;
-		else if (state->operation == AIO_OP_SEND)
-			state->operation = AIO_OP_SEND_JUST_CALLBACK;
-
-		ares = get_io_event (&list, MONO_POLLIN);
-		threadpool_append_job (&async_io_tp, ares);
-		if (list) {
-			ares = get_io_event (&list, MONO_POLLOUT);
-			threadpool_append_job (&async_io_tp, ares);
-		}
-	}
-}
-
-static void
-init_event_system (SocketIOData *data)
-{
-#ifdef HAVE_EPOLL
-	if (data->event_system == EPOLL_BACKEND) {
-		data->event_data = tp_epoll_init (data);
-		if (data->event_data == NULL) {
-			if (g_getenv ("MONO_DEBUG"))
-				g_message ("Falling back to poll()");
-			data->event_system = POLL_BACKEND;
-		}
-	}
-#elif defined(USE_KQUEUE_FOR_THREADPOOL)
-	if (data->event_system == KQUEUE_BACKEND)
-		data->event_data = tp_kqueue_init (data);
-#endif
-	if (data->event_system == POLL_BACKEND)
-		data->event_data = tp_poll_init (data);
-}
-
-static void
-socket_io_init (SocketIOData *data)
-{
-	int inited;
-
-	if (data->inited >= 2) // 2 -> initialized, 3-> cleaned up
-		return;
-
-	inited = InterlockedCompareExchange (&data->inited, 1, 0);
-	if (inited >= 1) {
-		while (TRUE) {
-			if (data->inited >= 2)
-				return;
-			SleepEx (1, FALSE);
-		}
-	}
-
-	mono_mutex_lock (&data->io_lock);
-	data->sock_to_state = mono_g_hash_table_new_type (g_direct_hash, g_direct_equal, MONO_HASH_VALUE_GC);
-#ifdef HAVE_EPOLL
-	data->event_system = EPOLL_BACKEND;
-#elif defined(USE_KQUEUE_FOR_THREADPOOL)
-	data->event_system = KQUEUE_BACKEND;
-#else
-	data->event_system = POLL_BACKEND;
-#endif
-	if (g_getenv ("MONO_DISABLE_AIO") != NULL)
-		data->event_system = POLL_BACKEND;
-
-	init_event_system (data);
-	mono_thread_create_internal (mono_get_root_domain (), data->wait, data, TRUE, SMALL_STACK);
-	mono_mutex_unlock (&data->io_lock);
-	data->inited = 2;
-	threadpool_start_thread (&async_io_tp);
-}
-
-static void
-socket_io_add (MonoAsyncResult *ares, MonoSocketAsyncResult *state)
-{
-	MonoMList *list;
-	SocketIOData *data = &socket_io_data;
-	int fd;
-	gboolean is_new;
-	int ievt;
-
-	socket_io_init (&socket_io_data);
-	if (mono_runtime_is_shutting_down () || data->inited == 3 || data->sock_to_state == NULL)
-		return;
-	if (async_tp.pool_status == 2)
-		return;
-
-	MONO_OBJECT_SETREF (state, ares, ares);
-
-	fd = GPOINTER_TO_INT (state->handle);
-	mono_mutex_lock (&data->io_lock);
-	if (data->sock_to_state == NULL) {
-		mono_mutex_unlock (&data->io_lock);
-		return;
-	}
-	list = mono_g_hash_table_lookup (data->sock_to_state, GINT_TO_POINTER (fd));
-	if (list == NULL) {
-		list = mono_mlist_alloc ((MonoObject*)state);
-		is_new = TRUE;
-	} else {
-		list = mono_mlist_append (list, (MonoObject*)state);
-		is_new = FALSE;
-	}
-
-	mono_g_hash_table_replace (data->sock_to_state, state->handle, list);
-	ievt = get_events_from_list (list);
-	/* The modify function leaves the io_lock critical section. */
-	data->modify (data, fd, state->operation, ievt, is_new);
-}
-
-#ifndef DISABLE_SOCKETS
-static gboolean
-socket_io_filter (MonoObject *target, MonoObject *state)
-{
-	gint op;
-	MonoSocketAsyncResult *sock_res;
-	MonoClass *klass;
-	MonoDomain *domain;
-
-	if (target == NULL || state == NULL)
-		return FALSE;
-
-	domain = target->vtable->domain;
-	klass = target->vtable->klass;
-	if (socket_async_call_klass == NULL && is_socketasynccall (domain, klass))
-		socket_async_call_klass = klass;
-
-	if (process_async_call_klass == NULL && is_sdp_asyncreadhandler (domain, klass))
-		process_async_call_klass = klass;
-
-	if (klass != socket_async_call_klass && klass != process_async_call_klass)
-		return FALSE;
-
-	sock_res = (MonoSocketAsyncResult *) state;
-	op = sock_res->operation;
-	if (op < AIO_OP_FIRST || op >= AIO_OP_LAST)
-		return FALSE;
-
-	return TRUE;
-}
-#endif /* !DISABLE_SOCKETS */
-
-/* Returns the exception thrown when invoking, if any */
-static MonoObject *
-mono_async_invoke (ThreadPool *tp, MonoAsyncResult *ares)
-{
-	MonoObject *exc = NULL;
-
-	mono_async_result_invoke (ares, &exc);
-
-#if DEBUG
-	InterlockedDecrement (&tp->njobs);
-#endif
-	if (!tp->is_io)
-		InterlockedIncrement (&tp->nexecuted);
-
-	if (InterlockedDecrement (&monitor_njobs) == 0)
-		monitor_state = MONITOR_STATE_FALLING_ASLEEP;
-
-	return exc;
-}
-
-static void
-threadpool_start_idle_threads (ThreadPool *tp)
-{
-	int n;
-	guint32 stack_size;
-
-	stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
-	do {
-		while (1) {
-			n = tp->nthreads;
-			if (n >= tp->min_threads)
-				return;
-			if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n)
-				break;
-		}
-#ifndef DISABLE_PERFCOUNTERS
-		mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
-#endif
-		mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
-		SleepEx (100, TRUE);
-	} while (1);
-}
-
-static void
-threadpool_init (ThreadPool *tp, int min_threads, int max_threads, void (*async_invoke) (gpointer))
-{
-	memset (tp, 0, sizeof (ThreadPool));
-	tp->min_threads = min_threads;
-	tp->max_threads = max_threads;
-	tp->async_invoke = async_invoke;
-	tp->queue = mono_cq_create ();
-	MONO_SEM_INIT (&tp->new_job, 0);
-}
-
-#ifndef DISABLE_PERFCOUNTERS
-static void *
-init_perf_counter (const char *category, const char *counter)
-{
-	MonoString *category_str;
-	MonoString *counter_str;
-	MonoString *machine;
-	MonoDomain *root;
-	MonoBoolean custom;
-	int type;
-
-	if (category == NULL || counter == NULL)
-		return NULL;
-	root = mono_get_root_domain ();
-	category_str = mono_string_new (root, category);
-	counter_str = mono_string_new (root, counter);
-	machine = mono_string_new (root, ".");
-	return mono_perfcounter_get_impl (category_str, counter_str, NULL, machine, &type, &custom);
-}
-#endif
-
-#ifdef DEBUG
-static void
-print_pool_info (ThreadPool *tp)
-{
-
-//	if (tp->tail - tp->head == 0)
-//		return;
-
-	g_print ("Pool status? %d\n", InterlockedCompareExchange (&tp->pool_status, 0, 0));
-	g_print ("Min. threads: %d\n", InterlockedCompareExchange (&tp->min_threads, 0, 0));
-	g_print ("Max. threads: %d\n", InterlockedCompareExchange (&tp->max_threads, 0, 0));
-	g_print ("nthreads: %d\n", InterlockedCompareExchange (&tp->nthreads, 0, 0));
-	g_print ("busy threads: %d\n", InterlockedCompareExchange (&tp->busy_threads, 0, 0));
-	g_print ("Waiting: %d\n", InterlockedCompareExchange (&tp->waiting, 0, 0));
-	g_print ("Queued: %d\n", (tp->tail - tp->head));
-	if (tp == &async_tp) {
-		int i;
-		mono_mutex_lock (&wsqs_lock);
-		for (i = 0; i < wsqs->len; i++) {
-			g_print ("\tWSQ %d: %d\n", i, mono_wsq_count (g_ptr_array_index (wsqs, i)));
-		}
-		mono_mutex_unlock (&wsqs_lock);
-	} else {
-		g_print ("\tSockets: %d\n", mono_g_hash_table_size (socket_io_data.sock_to_state));
-	}
-	g_print ("-------------\n");
-}
-
-static void
-signal_handler (int signo)
-{
-	ThreadPool *tp;
-
-	tp = &async_tp;
-	g_print ("\n-----Non-IO-----\n");
-	print_pool_info (tp);
-	tp = &async_io_tp;
-	g_print ("\n-----IO-----\n");
-	print_pool_info (tp);
-	alarm (2);
-}
-#endif
-
-#define SAMPLES_PERIOD 500
-#define HISTORY_SIZE 10
-/* number of iteration without any jobs
-   in the queue before going to sleep */
-#define NUM_WAITING_ITERATIONS 10
-
-typedef struct {
-	gint32 nexecuted;
-	gint32 nthreads;
-	gint8 nthreads_diff;
-} SamplesHistory;
-
-/*
- * returns :
- *  -  1 if the number of threads should increase
- *  -  0 if it should not change
- *  - -1 if it should decrease
- *  - -2 in case of error
- */
-static gint8
-monitor_heuristic (gint16 *current, gint16 *history_size, SamplesHistory *history, ThreadPool *tp)
-{
-	int i;
-	gint8 decision G_GNUC_UNUSED;
-	gint16 cur, max = 0;
-	gboolean all_waitsleepjoin;
-	MonoInternalThread *thread;
-
-	/*
-	 * The following heuristic tries to approach the optimal number of threads to maximize jobs throughput. To
-	 * achieve this, it simply stores the number of jobs executed (nexecuted), the number of Threads (nthreads)
-	 * and the decision (nthreads_diff) for the past HISTORY_SIZE periods of time, each period being of
-	 * duration SAMPLES_PERIOD ms. This history gives us an insight into what happened, and to see if we should
-	 * increase or reduce the number of threads by comparing the last period (current) to the best one.
-	 *
-	 * The algorithm can be describe as following :
-	 *  - if we have a better throughput than the best period : we should either increase the number of threads
-	 *     in case we already have more threads, either reduce the number of threads if we have less threads; this
-	 *     is equivalent to move away from the number of threads of the best period, because we are currently better
-	 *  - if we have a worse throughput than the best period : we should either decrease the number of threads if
-	 *     we have more threads, either increase the number of threads if we have less threads;  this is equivalent
-	 *     to get closer to the number of threads of the best period, because we are currently worse
-	 */
-
-	*history_size = MIN (*history_size + 1, HISTORY_SIZE);
-	cur = *current = (*current + 1) % *history_size;
-
-	history [cur].nthreads = tp->nthreads;
-	history [cur].nexecuted = InterlockedExchange (&tp->nexecuted, 0);
-
-	if (tp->waiting) {
-		/* if we have waiting thread in the pool, then do not create a new one */
-		history [cur].nthreads_diff = tp->waiting > 1 ? -1 : 0;
-		decision = 0;
-	} else if (tp->nthreads < tp->min_threads) {
-		history [cur].nthreads_diff = 1;
-		decision = 1;
-	} else if (*history_size <= 1) {
-		/* first iteration, let's add a thread by default */
-		history [cur].nthreads_diff = 1;
-		decision = 2;
-	} else {
-		mono_mutex_lock (&threads_lock);
-		if (threads == NULL) {
-			mono_mutex_unlock (&threads_lock);
-			return -2;
-		}
-		all_waitsleepjoin = TRUE;
-		for (i = 0; i < threads->len; ++i) {
-			thread = g_ptr_array_index (threads, i);
-			if (!(thread->state & ThreadState_WaitSleepJoin)) {
-				all_waitsleepjoin = FALSE;
-				break;
-			}
-		}
-		mono_mutex_unlock (&threads_lock);
-
-		if (all_waitsleepjoin) {
-			/* we might be in a condition of starvation/deadlock with tasks waiting for each others */
-			history [cur].nthreads_diff = 1;
-			decision = 5;
-		} else {
-			max = cur == 0 ? 1 : 0;
-			for (i = 0; i < *history_size; i++) {
-				if (i == cur)
-					continue;
-				if (history [i].nexecuted > history [max].nexecuted)
-					max = i;
-			}
-
-			if (history [cur].nexecuted >= history [max].nexecuted) {
-				/* we improved the situation, let's continue ! */
-				history [cur].nthreads_diff = history [cur].nthreads >= history [max].nthreads ? 1 : -1;
-				decision = 3;
-			} else {
-				/* we made it worse, let's return to previous situation */
-				history [cur].nthreads_diff = history [cur].nthreads >= history [max].nthreads ? -1 : 1;
-				decision = 4;
-			}
-		}
-	}
-
-#if DEBUG
-	printf ("monitor_thread: decision: %1d, history [current]: {nexecuted: %5d, nthreads: %3d, waiting: %2d, nthreads_diff: %2d}, history [max]: {nexecuted: %5d, nthreads: %3d}\n",
-			decision, history [cur].nexecuted, history [cur].nthreads, tp->waiting, history [cur].nthreads_diff, history [max].nexecuted, history [max].nthreads);
-#endif
-	
-	return history [cur].nthreads_diff;
-}
-
-static void
-monitor_thread (gpointer unused)
-{
-	ThreadPool *pools [2];
-	MonoInternalThread *thread;
-	int i;
-
-	guint32 ms;
-	gint8 num_waiting_iterations = 0;
-
-	gint16 history_size = 0, current = -1;
-	SamplesHistory *history = malloc (sizeof (SamplesHistory) * HISTORY_SIZE);
-
-	pools [0] = &async_tp;
-	pools [1] = &async_io_tp;
-	thread = mono_thread_internal_current ();
-	ves_icall_System_Threading_Thread_SetName_internal (thread, mono_string_new (mono_domain_get (), "Threadpool monitor"));
-	while (1) {
-		ms = SAMPLES_PERIOD;
-		i = 10; //number of spurious awakes we tolerate before doing a round of rebalancing.
-		mono_gc_set_skip_thread (TRUE);
-		MONO_PREPARE_BLOCKING
-		do {
-			guint32 ts;
-			ts = mono_msec_ticks ();
-			if (SleepEx (ms, TRUE) == 0)
-				break;
-			ms -= (mono_msec_ticks () - ts);
-			if (mono_runtime_is_shutting_down ())
-				break;
-			check_for_interruption_critical ();
-		} while (ms > 0 && i--);
-		MONO_FINISH_BLOCKING
-		mono_gc_set_skip_thread (FALSE);
-
-		if (mono_runtime_is_shutting_down ())
-			break;
-
-		if (suspended)
-			continue;
-
-		/* threadpool is cleaning up */
-		if (async_tp.pool_status == 2 || async_io_tp.pool_status == 2)
-			break;
-
-		MONO_PREPARE_BLOCKING
-		switch (monitor_state) {
-		case MONITOR_STATE_AWAKE:
-			num_waiting_iterations = 0;
-			break;
-		case MONITOR_STATE_FALLING_ASLEEP:
-			if (++num_waiting_iterations == NUM_WAITING_ITERATIONS) {
-				if (monitor_state == MONITOR_STATE_FALLING_ASLEEP && InterlockedCompareExchange (&monitor_state, MONITOR_STATE_SLEEPING, MONITOR_STATE_FALLING_ASLEEP) == MONITOR_STATE_FALLING_ASLEEP) {
-					MONO_SEM_WAIT (&monitor_sem);
-
-					num_waiting_iterations = 0;
-					current = -1;
-					history_size = 0;
-				}
-			}
-			break;
-		case MONITOR_STATE_SLEEPING:
-			g_assert_not_reached ();
-		}
-		MONO_FINISH_BLOCKING
-
-		for (i = 0; i < 2; i++) {
-			ThreadPool *tp;
-			tp = pools [i];
-
-			if (tp->is_io) {
-				if (!tp->waiting && mono_cq_count (tp->queue) > 0)
-					threadpool_start_thread (tp);
-			} else {
-				gint8 nthreads_diff = monitor_heuristic (&current, &history_size, history, tp);
-
-				if (nthreads_diff == 1)
-					threadpool_start_thread (tp);
-				else if (nthreads_diff == -1)
-					threadpool_kill_thread (tp);
-			}
-		}
-	}
-}
-
-void
-mono_thread_pool_init_tls (void)
-{
-	if (use_ms_threadpool ()) {
-		mono_threadpool_ms_init_tls ();
-		return;
-	}
-
-	mono_wsq_init ();
-}
-
-void
-mono_thread_pool_init (void)
-{
-	gint threads_per_cpu = 1;
-	gint thread_count;
-	gint cpu_count;
-	int result;
-	
-	if (use_ms_threadpool ()) {
-		mono_threadpool_ms_init ();
-		return;
-	}
-
-	cpu_count = mono_cpu_count ();
-
-	if (tp_inited == 2)
-		return;
-
-	result = InterlockedCompareExchange (&tp_inited, 1, 0);
-	if (result == 1) {
-		while (1) {
-			SleepEx (1, FALSE);
-			if (tp_inited == 2)
-				return;
-		}
-	}
-
-	MONO_GC_REGISTER_ROOT_FIXED (socket_io_data.sock_to_state);
-	mono_mutex_init_recursive (&socket_io_data.io_lock);
-	if (g_getenv ("MONO_THREADS_PER_CPU") != NULL) {
-		threads_per_cpu = atoi (g_getenv ("MONO_THREADS_PER_CPU"));
-		if (threads_per_cpu < 1)
-			threads_per_cpu = 1;
-	}
-
-	thread_count = MIN (cpu_count * threads_per_cpu, 100 * cpu_count);
-	threadpool_init (&async_tp, thread_count, MAX (100 * cpu_count, thread_count), async_invoke_thread);
-	threadpool_init (&async_io_tp, cpu_count * 2, cpu_count * 4, async_invoke_thread);
-	async_io_tp.is_io = TRUE;
-
-	async_call_klass = mono_class_from_name (mono_defaults.corlib, "System", "MonoAsyncCall");
-	g_assert (async_call_klass);
-
-	mono_mutex_init (&threads_lock);
-	threads = g_ptr_array_sized_new (thread_count);
-	g_assert (threads);
-
-	mono_mutex_init_recursive (&wsqs_lock);
-	wsqs = g_ptr_array_sized_new (MAX (100 * cpu_count, thread_count));
-
-#ifndef DISABLE_PERFCOUNTERS
-	async_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "Work Items Added");
-	g_assert (async_tp.pc_nitems);
-
-	async_io_tp.pc_nitems = init_perf_counter ("Mono Threadpool", "IO Work Items Added");
-	g_assert (async_io_tp.pc_nitems);
-
-	async_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of Threads");
-	g_assert (async_tp.pc_nthreads);
-
-	async_io_tp.pc_nthreads = init_perf_counter ("Mono Threadpool", "# of IO Threads");
-	g_assert (async_io_tp.pc_nthreads);
-#endif
-	tp_inited = 2;
-#ifdef DEBUG
-	signal (SIGALRM, signal_handler);
-	alarm (2);
-#endif
-
-	MONO_SEM_INIT (&monitor_sem, 0);
-	monitor_state = MONITOR_STATE_AWAKE;
-	monitor_njobs = 0;
-}
-
-static MonoAsyncResult *
-create_simple_asyncresult (MonoObject *target, MonoObject *state)
-{
-	MonoDomain *domain = mono_domain_get ();
-	MonoAsyncResult *ares;
-
-	/* Don't call mono_async_result_new() to avoid capturing the context */
-	ares = (MonoAsyncResult *) mono_object_new (domain, mono_defaults.asyncresult_class);
-	MONO_OBJECT_SETREF (ares, async_delegate, target);
-	MONO_OBJECT_SETREF (ares, async_state, state);
-	return ares;
-}
-
-void
-icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state)
-{
-	MonoAsyncResult *ares;
-
-	ares = create_simple_asyncresult (target, (MonoObject *) state);
-
-	if (use_ms_threadpool ()) {
-#ifndef DISABLE_SOCKETS
-		mono_threadpool_ms_io_add (ares, state);
-#endif
-		return;
-	}
-
-	socket_io_add (ares, state);
-}
-
-MonoAsyncResult *
-mono_thread_pool_begin_invoke (MonoDomain *domain, MonoObject *target, MonoMethod *method, gpointer *params)
-{
-	MonoMethodMessage *message;
-	MonoAsyncResult *async_result;
-	MonoAsyncCall *async_call;
-	MonoDelegate *async_callback = NULL;
-	MonoObject *state = NULL;
-
-	if (use_ms_threadpool ())
-		return mono_threadpool_ms_begin_invoke (domain, target, method, params);
-
-	message = mono_method_call_message_new (method, params, mono_get_delegate_invoke (method->klass), (params != NULL) ? (&async_callback) : NULL, (params != NULL) ? (&state) : NULL);
-
-	async_call = (MonoAsyncCall*)mono_object_new (domain, async_call_klass);
-	MONO_OBJECT_SETREF (async_call, msg, message);
-	MONO_OBJECT_SETREF (async_call, state, state);
-
-	if (async_callback) {
-		async_call->cb_method = mono_get_delegate_invoke (((MonoObject*) async_callback)->vtable->klass);
-		MONO_OBJECT_SETREF (async_call, cb_target, async_callback);
-	}
-
-	async_result = mono_async_result_new (domain, NULL, async_call->state, NULL, (MonoObject*) async_call);
-	MONO_OBJECT_SETREF (async_result, async_delegate, target);
-
-#ifndef DISABLE_SOCKETS
-	if (socket_io_filter (target, state)) {
-		socket_io_add (async_result, (MonoSocketAsyncResult *) state);
-		return async_result;
-	}
-#endif
-	threadpool_append_job (&async_tp, (MonoObject *) async_result);
-	return async_result;
-}
-
-MonoObject *
-mono_thread_pool_end_invoke (MonoAsyncResult *ares, MonoArray **out_args, MonoObject **exc)
-{
-	MonoAsyncCall *ac;
-	HANDLE wait_event;
-
-	if (use_ms_threadpool ()) {
-		return mono_threadpool_ms_end_invoke (ares, out_args, exc);
-	}
-
-	*exc = NULL;
-	*out_args = NULL;
-
-	/* check if already finished */
-	mono_monitor_enter ((MonoObject *) ares);
-	
-	if (ares->endinvoke_called) {
-		*exc = (MonoObject *) mono_get_exception_invalid_operation (NULL);
-		mono_monitor_exit ((MonoObject *) ares);
-		return NULL;
-	}
-
-	ares->endinvoke_called = 1;
-	/* wait until we are really finished */
-	if (!ares->completed) {
-		if (ares->handle == NULL) {
-			wait_event = CreateEvent (NULL, TRUE, FALSE, NULL);
-			g_assert(wait_event != 0);
-			MONO_OBJECT_SETREF (ares, handle, (MonoObject *) mono_wait_handle_new (mono_object_domain (ares), wait_event));
-		} else {
-			wait_event = mono_wait_handle_get_handle ((MonoWaitHandle *) ares->handle);
-		}
-		mono_monitor_exit ((MonoObject *) ares);
-		MONO_PREPARE_BLOCKING
-		WaitForSingleObjectEx (wait_event, INFINITE, TRUE);
-		MONO_FINISH_BLOCKING
-	} else {
-		mono_monitor_exit ((MonoObject *) ares);
-	}
-
-	ac = (MonoAsyncCall *) ares->object_data;
-	g_assert (ac != NULL);
-	*exc = ac->msg->exc; /* FIXME: GC add write barrier */
-	*out_args = ac->out_args;
-
-	return ac->res;
-}
-
-static void
-threadpool_kill_idle_threads (ThreadPool *tp)
-{
-	gint n;
-
-	n = (gint) InterlockedCompareExchange (&tp->max_threads, 0, -1);
-	while (n) {
-		n--;
-		MONO_SEM_POST (&tp->new_job);
-	}
-}
-
-void
-mono_thread_pool_cleanup (void)
-{
-	if (use_ms_threadpool ()) {
-		mono_threadpool_ms_cleanup ();
-		return;
-	}
-
-	if (InterlockedExchange (&async_io_tp.pool_status, 2) == 1) {
-		socket_io_cleanup (&socket_io_data); /* Empty when DISABLE_SOCKETS is defined */
-		threadpool_kill_idle_threads (&async_io_tp);
-	}
-
-	if (async_io_tp.queue != NULL) {
-		MONO_SEM_DESTROY (&async_io_tp.new_job);
-		threadpool_free_queue (&async_io_tp);
-	}
-
-
-	if (InterlockedExchange (&async_tp.pool_status, 2) == 1) {
-		threadpool_kill_idle_threads (&async_tp);
-		threadpool_free_queue (&async_tp);
-	}
-	
-	if (threads) {
-		mono_mutex_lock (&threads_lock);
-		if (threads)
-			g_ptr_array_free (threads, FALSE);
-		threads = NULL;
-		mono_mutex_unlock (&threads_lock);
-	}
-
-	if (wsqs) {
-		mono_mutex_lock (&wsqs_lock);
-		mono_wsq_cleanup ();
-		if (wsqs)
-			g_ptr_array_free (wsqs, TRUE);
-		wsqs = NULL;
-		mono_mutex_unlock (&wsqs_lock);
-		MONO_SEM_DESTROY (&async_tp.new_job);
-	}
-
-	MONO_SEM_DESTROY (&monitor_sem);
-}
-
-static gboolean
-threadpool_start_thread (ThreadPool *tp)
-{
-	gint n;
-	guint32 stack_size;
-	MonoInternalThread *thread;
-
-	stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
-	while (!mono_runtime_is_shutting_down () && (n = tp->nthreads) < tp->max_threads) {
-		if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n) {
-#ifndef DISABLE_PERFCOUNTERS
-			mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
-#endif
-			if (tp->is_io) {
-				thread = mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
-			} else {
-				mono_mutex_lock (&threads_lock);
-				thread = mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
-				g_assert (threads != NULL);
-				g_ptr_array_add (threads, thread);
-				mono_mutex_unlock (&threads_lock);
-			}
-			return TRUE;
-		}
-	}
-
-	return FALSE;
-}
-
-static void
-pulse_on_new_job (ThreadPool *tp)
-{
-	if (tp->waiting)
-		MONO_SEM_POST (&tp->new_job);
-}
-
-static void
-threadpool_kill_thread (ThreadPool *tp)
-{
-	if (tp->destroy_thread == 0 && InterlockedCompareExchange (&tp->destroy_thread, 1, 0) == 0)
-		pulse_on_new_job (tp);
-}
-
-void
-icall_append_job (MonoObject *ar)
-{
-	threadpool_append_jobs (&async_tp, &ar, 1);
-}
-
-static void
-threadpool_append_job (ThreadPool *tp, MonoObject *ar)
-{
-	threadpool_append_jobs (tp, &ar, 1);
-}
-
-void
-threadpool_append_async_io_jobs (MonoObject **jobs, gint njobs)
-{
-	threadpool_append_jobs (&async_io_tp, jobs, njobs);
-}
-
-static void
-threadpool_append_jobs (ThreadPool *tp, MonoObject **jobs, gint njobs)
-{
-	MonoObject *ar;
-	gint i;
-
-	if (mono_runtime_is_shutting_down ())
-		return;
-
-	if (tp->pool_status == 0 && InterlockedCompareExchange (&tp->pool_status, 1, 0) == 0) {
-		if (!tp->is_io) {
-			monitor_internal_thread = mono_thread_create_internal (mono_get_root_domain (), monitor_thread, NULL, TRUE, SMALL_STACK);
-			monitor_internal_thread->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
-			threadpool_start_thread (tp);
-		}
-		/* Create on demand up to min_threads to avoid startup penalty for apps that don't use
-		 * the threadpool that much
-		 */
-		if (mono_config_is_server_mode ()) {
-			mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, tp, TRUE, SMALL_STACK);
-		}
-	}
-
-	InterlockedAdd (&monitor_njobs, njobs);
-
-	if (monitor_state == MONITOR_STATE_SLEEPING && InterlockedCompareExchange (&monitor_state, MONITOR_STATE_AWAKE, MONITOR_STATE_SLEEPING) == MONITOR_STATE_SLEEPING)
-		MONO_SEM_POST (&monitor_sem);
-
-	if (monitor_state == MONITOR_STATE_FALLING_ASLEEP)
-		InterlockedCompareExchange (&monitor_state, MONITOR_STATE_AWAKE, MONITOR_STATE_FALLING_ASLEEP);
-
-	for (i = 0; i < njobs; i++) {
-		ar = jobs [i];
-		if (ar == NULL || mono_domain_is_unloading (ar->vtable->domain))
-			continue; /* Might happen when cleaning domain jobs */
-		threadpool_jobs_inc (ar); 
-#ifndef DISABLE_PERFCOUNTERS
-		mono_perfcounter_update_value (tp->pc_nitems, TRUE, 1);
-#endif
-		if (!tp->is_io && mono_wsq_local_push (ar))
-			continue;
-
-		mono_cq_enqueue (tp->queue, ar);
-	}
-
-#if DEBUG
-	InterlockedAdd (&tp->njobs, njobs);
-#endif
-
-	for (i = 0; tp->waiting > 0 && i < MIN(njobs, tp->max_threads); i++)
-		pulse_on_new_job (tp);
-}
-
-static void
-threadpool_clear_queue (ThreadPool *tp, MonoDomain *domain)
-{
-	MonoObject *obj;
-	MonoMList *other = NULL;
-	MonoCQ *queue = tp->queue;
-
-	if (!queue)
-		return;
-
-	while (mono_cq_dequeue (queue, &obj)) {
-		if (obj == NULL)
-			continue;
-		if (obj->vtable->domain != domain)
-			other = mono_mlist_prepend (other, obj);
-		threadpool_jobs_dec (obj);
-	}
-
-	if (mono_runtime_is_shutting_down ())
-		return;
-
-	while (other) {
-		threadpool_append_job (tp, (MonoObject *) mono_mlist_get_data (other));
-		other = mono_mlist_next (other);
-	}
-}
-
-static gboolean
-remove_sockstate_for_domain (gpointer key, gpointer value, gpointer user_data)
-{
-	MonoMList *list = value;
-	gboolean remove = FALSE;
-	while (list) {
-		MonoObject *data = mono_mlist_get_data (list);
-		if (mono_object_domain (data) == user_data) {
-			remove = TRUE;
-			mono_mlist_set_data (list, NULL);
-		}
-		list = mono_mlist_next (list);
-	}
-	//FIXME is there some sort of additional unregistration we need to perform here?
-	return remove;
-}
-
-/*
- * Clean up the threadpool of all domain jobs.
- * Can only be called as part of the domain unloading process as
- * it will wait for all jobs to be visible to the interruption code. 
- */
-gboolean
-mono_thread_pool_remove_domain_jobs (MonoDomain *domain, int timeout)
-{
-	HANDLE sem_handle;
-	int result;
-	guint32 start_time;
-
-	if (use_ms_threadpool ()) {
-		return mono_threadpool_ms_remove_domain_jobs (domain, timeout);
-	}
-
-	result = TRUE;
-	start_time = 0;
-
-	g_assert (domain->state == MONO_APPDOMAIN_UNLOADING);
-
-	threadpool_clear_queue (&async_tp, domain);
-	threadpool_clear_queue (&async_io_tp, domain);
-
-	mono_mutex_lock (&socket_io_data.io_lock);
-	if (socket_io_data.sock_to_state)
-		mono_g_hash_table_foreach_remove (socket_io_data.sock_to_state, remove_sockstate_for_domain, domain);
-
-	mono_mutex_unlock (&socket_io_data.io_lock);
-	
-	/*
-	 * There might be some threads out that could be about to execute stuff from the given domain.
-	 * We avoid that by setting up a semaphore to be pulsed by the thread that reaches zero.
-	 */
-	sem_handle = CreateSemaphore (NULL, 0, 1, NULL);
-
-	domain->cleanup_semaphore = sem_handle;
-	/*
-	 * The memory barrier here is required to have global ordering between assigning to cleanup_semaphone
-	 * and reading threadpool_jobs.
-	 * Otherwise this thread could read a stale version of threadpool_jobs and wait forever.
-	 */
-	mono_memory_write_barrier ();
-
-	if (domain->threadpool_jobs && timeout != -1)
-		start_time = mono_msec_ticks ();
-	while (domain->threadpool_jobs) {
-		MONO_PREPARE_BLOCKING
-		WaitForSingleObject (sem_handle, timeout);
-		MONO_FINISH_BLOCKING
-		if (timeout != -1 && (mono_msec_ticks () - start_time) > timeout) {
-			result = FALSE;
-			break;
-		}
-	}
-
-	domain->cleanup_semaphore = NULL;
-	CloseHandle (sem_handle);
-	return result;
-}
-
-static void
-threadpool_free_queue (ThreadPool *tp)
-{
-	mono_cq_destroy (tp->queue);
-	tp->queue = NULL;
-}
-
-gboolean
-mono_thread_pool_is_queue_array (MonoArray *o)
-{
-	if (use_ms_threadpool ()) {
-		return mono_threadpool_ms_is_queue_array (o);
-	}
-
-	// gpointer obj = o;
-
-	// FIXME: need some fix in sgen code.
-	return FALSE;
-}
-
-static MonoWSQ *
-add_wsq (void)
-{
-	int i;
-	MonoWSQ *wsq;
-
-	mono_mutex_lock (&wsqs_lock);
-	wsq = mono_wsq_create ();
-	if (wsqs == NULL) {
-		mono_mutex_unlock (&wsqs_lock);
-		return NULL;
-	}
-	for (i = 0; i < wsqs->len; i++) {
-		if (g_ptr_array_index (wsqs, i) == NULL) {
-			wsqs->pdata [i] = wsq;
-			mono_mutex_unlock (&wsqs_lock);
-			return wsq;
-		}
-	}
-	g_ptr_array_add (wsqs, wsq);
-	mono_mutex_unlock (&wsqs_lock);
-	return wsq;
-}
-
-static void
-remove_wsq (MonoWSQ *wsq)
-{
-	gpointer data;
-
-	if (wsq == NULL)
-		return;
-
-	mono_mutex_lock (&wsqs_lock);
-	if (wsqs == NULL) {
-		mono_mutex_unlock (&wsqs_lock);
-		return;
-	}
-	g_ptr_array_remove_fast (wsqs, wsq);
-	data = NULL;
-	/*
-	 * Only clean this up when shutting down, any other case will error out
-	 * if we're removing a queue that still has work items.
-	 */
-	if (mono_runtime_is_shutting_down ()) {
-		while (mono_wsq_local_pop (&data)) {
-			threadpool_jobs_dec (data);
-			data = NULL;
-		}
-	}
-	mono_wsq_destroy (wsq);
-	mono_mutex_unlock (&wsqs_lock);
-}
-
-static void
-try_steal (MonoWSQ *local_wsq, gpointer *data, gboolean retry)
-{
-	int i;
-	int ms;
-
-	if (wsqs == NULL || data == NULL || *data != NULL)
-		return;
-
-	ms = 0;
-	do {
-		if (mono_runtime_is_shutting_down ())
-			return;
-
-		MONO_PREPARE_BLOCKING
-		mono_mutex_lock (&wsqs_lock);
-		MONO_FINISH_BLOCKING
-		for (i = 0; wsqs != NULL && i < wsqs->len; i++) {
-			MonoWSQ *wsq;
-
-			wsq = wsqs->pdata [i];
-			if (wsq == local_wsq || mono_wsq_count (wsq) == 0)
-				continue;
-			mono_wsq_try_steal (wsqs->pdata [i], data, ms);
-			if (*data != NULL) {
-				mono_mutex_unlock (&wsqs_lock);
-				return;
-			}
-		}
-		mono_mutex_unlock (&wsqs_lock);
-		ms += 10;
-	} while (retry && ms < 11);
-}
-
-static gboolean
-dequeue_or_steal (ThreadPool *tp, gpointer *data, MonoWSQ *local_wsq)
-{
-	MonoCQ *queue = tp->queue;
-	if (mono_runtime_is_shutting_down () || !queue)
-		return FALSE;
-	mono_cq_dequeue (queue, (MonoObject **) data);
-	if (!tp->is_io && !*data)
-		try_steal (local_wsq, data, FALSE);
-	return (*data != NULL);
-}
-
-static gboolean
-should_i_die (ThreadPool *tp)
-{
-	gboolean result = FALSE;
-	if (tp->destroy_thread == 1 && InterlockedCompareExchange (&tp->destroy_thread, 0, 1) == 1)
-		result = (tp->nthreads > tp->min_threads);
-	return result;
-}
-
-static void
-set_tp_thread_info (ThreadPool *tp)
-{
-	const gchar *name;
-	MonoInternalThread *thread = mono_thread_internal_current ();
-
-	mono_profiler_thread_start (thread->tid);
-	name = (tp->is_io) ? "IO Threadpool worker" : "Threadpool worker";
-	mono_thread_set_name_internal (thread, mono_string_new (mono_domain_get (), name), FALSE);
-}
-
-static void
-clear_thread_state (void)
-{
-	MonoInternalThread *thread = mono_thread_internal_current ();
-	/* If the callee changes the background status, set it back to TRUE */
-	mono_thread_clr_state (thread , ~ThreadState_Background);
-	if (!mono_thread_test_state (thread , ThreadState_Background))
-		ves_icall_System_Threading_Thread_SetState (thread, ThreadState_Background);
-}
-
-void
-check_for_interruption_critical (void)
-{
-	MonoInternalThread *thread;
-	/*RULE NUMBER ONE OF SKIP_THREAD: NEVER POKE MANAGED STATE.*/
-	mono_gc_set_skip_thread (FALSE);
-
-	thread = mono_thread_internal_current ();
-	if (THREAD_WANTS_A_BREAK (thread))
-		mono_thread_interruption_checkpoint ();
-
-	/*RULE NUMBER TWO OF SKIP_THREAD: READ RULE NUMBER ONE.*/
-	mono_gc_set_skip_thread (TRUE);
-}
-
-static void
-fire_profiler_thread_end (void)
-{
-	MonoInternalThread *thread = mono_thread_internal_current ();
-	mono_profiler_thread_end (thread->tid);
-}
-
-static void
-async_invoke_thread (gpointer data)
-{
-	MonoDomain *domain;
-	MonoWSQ *wsq;
-	ThreadPool *tp;
-	gboolean must_die;
-  
-	tp = data;
-	wsq = NULL;
-	if (!tp->is_io)
-		wsq = add_wsq ();
-
-	set_tp_thread_info (tp);
-
-	if (tp_start_func)
-		tp_start_func (tp_hooks_user_data);
-
-	data = NULL;
-	for (;;) {
-		MonoAsyncResult *ar;
-		MonoClass *klass;
-		gboolean is_io_task;
-		gboolean is_socket;
-		int n_naps = 0;
-
-		is_io_task = FALSE;
-		ar = (MonoAsyncResult *) data;
-		if (ar) {
-			InterlockedIncrement (&tp->busy_threads);
-			domain = ((MonoObject *)ar)->vtable->domain;
-#ifndef DISABLE_SOCKETS
-			klass = ((MonoObject *) data)->vtable->klass;
-			is_io_task = !is_corlib_asyncresult (domain, klass);
-			is_socket = FALSE;
-			if (is_io_task) {
-				MonoSocketAsyncResult *state = (MonoSocketAsyncResult *) data;
-				is_socket = is_socketasyncresult (domain, klass);
-				ar = state->ares;
-			}
-#endif
-			/* worker threads invokes methods in different domains,
-			 * so we need to set the right domain here */
-			g_assert (domain);
-
-			if (mono_domain_is_unloading (domain) || mono_runtime_is_shutting_down ()) {
-				threadpool_jobs_dec ((MonoObject *)ar);
-				data = NULL;
-				ar = NULL;
-				InterlockedDecrement (&tp->busy_threads);
-			} else {
-				mono_thread_push_appdomain_ref (domain);
-				if (threadpool_jobs_dec ((MonoObject *)ar)) {
-					data = NULL;
-					ar = NULL;
-					mono_thread_pop_appdomain_ref ();
-					InterlockedDecrement (&tp->busy_threads);
-					continue;
-				}
-
-				if (mono_domain_set (domain, FALSE)) {
-					MonoObject *exc;
-
-					if (tp_item_begin_func)
-						tp_item_begin_func (tp_item_user_data);
-
-					exc = mono_async_invoke (tp, ar);
-					if (tp_item_end_func)
-						tp_item_end_func (tp_item_user_data);
-					if (exc)
-						mono_internal_thread_unhandled_exception (exc);
-					if (is_socket && tp->is_io) {
-						MonoSocketAsyncResult *state = (MonoSocketAsyncResult *) data;
-
-						if (state->completed && state->callback) {
-							MonoAsyncResult *cb_ares;
-							cb_ares = create_simple_asyncresult ((MonoObject *) state->callback,
-												(MonoObject *) state);
-							icall_append_job ((MonoObject *) cb_ares);
-						}
-					}
-					mono_domain_set (mono_get_root_domain (), TRUE);
-				}
-				mono_thread_pop_appdomain_ref ();
-				InterlockedDecrement (&tp->busy_threads);
-				clear_thread_state ();
-			}
-		}
-
-		ar = NULL;
-		data = NULL;
-		must_die = should_i_die (tp);
-		if (must_die) {
-			mono_wsq_suspend (wsq);
-		} else {
-			if (tp->is_io || !mono_wsq_local_pop (&data))
-				dequeue_or_steal (tp, &data, wsq);
-		}
-
-		n_naps = 0;
-		while (!must_die && !data && n_naps < 4) {
-			gboolean res;
-
-			InterlockedIncrement (&tp->waiting);
-
-			// Another thread may have added a job into its wsq since the last call to dequeue_or_steal
-			// Check all the queues again before entering the wait loop
-			dequeue_or_steal (tp, &data, wsq);
-			if (data) {
-				InterlockedDecrement (&tp->waiting);
-				break;
-			}
-
-			mono_gc_set_skip_thread (TRUE);
-			MONO_PREPARE_BLOCKING
-
-#if defined(__OpenBSD__)
-			while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_wait (&tp->new_job, TRUE)) == -1) {// && errno == EINTR) {
-#else
-			while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_timedwait (&tp->new_job, 2000, TRUE)) == -1) {// && errno == EINTR) {
-#endif
-				if (mono_runtime_is_shutting_down ())
-					break;
-				check_for_interruption_critical ();
-			}
-			InterlockedDecrement (&tp->waiting);
-
-			MONO_FINISH_BLOCKING
-			mono_gc_set_skip_thread (FALSE);
-
-			if (mono_runtime_is_shutting_down ())
-				break;
-			must_die = should_i_die (tp);
-			dequeue_or_steal (tp, &data, wsq);
-			n_naps++;
-		}
-
-		if (!data && !tp->is_io && !mono_runtime_is_shutting_down ()) {
-			mono_wsq_local_pop (&data);
-			if (data && must_die) {
-				InterlockedCompareExchange (&tp->destroy_thread, 1, 0);
-				pulse_on_new_job (tp);
-			}
-		}
-
-		if (!data) {
-			gint nt;
-			gboolean down;
-			while (1) {
-				nt = tp->nthreads;
-				down = mono_runtime_is_shutting_down ();
-				if (!down && nt <= tp->min_threads)
-					break;
-				if (down || InterlockedCompareExchange (&tp->nthreads, nt - 1, nt) == nt) {
-#ifndef DISABLE_PERFCOUNTERS
-					mono_perfcounter_update_value (tp->pc_nthreads, TRUE, -1);
-#endif
-					if (!tp->is_io) {
-						remove_wsq (wsq);
-					}
-
-					fire_profiler_thread_end ();
-
-					if (tp_finish_func)
-						tp_finish_func (tp_hooks_user_data);
-
-					if (!tp->is_io) {
-						if (threads) {
-							mono_mutex_lock (&threads_lock);
-							if (threads)
-								g_ptr_array_remove_fast (threads, mono_thread_current ()->internal_thread);
-							mono_mutex_unlock (&threads_lock);
-						}
-					}
-
-					return;
-				}
-			}
-		}
-	}
-
-	g_assert_not_reached ();
-}
-
-void
-ves_icall_System_Threading_ThreadPool_GetAvailableThreads (gint *workerThreads, gint *completionPortThreads)
-{
-	*workerThreads = async_tp.max_threads - async_tp.busy_threads;
-	*completionPortThreads = async_io_tp.max_threads - async_io_tp.busy_threads;
-}
-
-void
-ves_icall_System_Threading_ThreadPool_GetMaxThreads (gint *workerThreads, gint *completionPortThreads)
-{
-	*workerThreads = async_tp.max_threads;
-	*completionPortThreads = async_io_tp.max_threads;
-}
-
-void
-ves_icall_System_Threading_ThreadPool_GetMinThreads (gint *workerThreads, gint *completionPortThreads)
-{
-	*workerThreads = async_tp.min_threads;
-	*completionPortThreads = async_io_tp.min_threads;
-}
-
-MonoBoolean
-ves_icall_System_Threading_ThreadPool_SetMinThreads (gint workerThreads, gint completionPortThreads)
-{
-	gint max_threads;
-	gint max_io_threads;
-
-	max_threads = async_tp.max_threads;
-	if (workerThreads <= 0 || workerThreads > max_threads)
-		return FALSE;
-
-	max_io_threads = async_io_tp.max_threads;
-	if (completionPortThreads <= 0 || completionPortThreads > max_io_threads)
-		return FALSE;
-
-	InterlockedExchange (&async_tp.min_threads, workerThreads);
-	InterlockedExchange (&async_io_tp.min_threads, completionPortThreads);
-	if (workerThreads > async_tp.nthreads)
-		mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_tp, TRUE, SMALL_STACK);
-	if (completionPortThreads > async_io_tp.nthreads)
-		mono_thread_create_internal (mono_get_root_domain (), threadpool_start_idle_threads, &async_io_tp, TRUE, SMALL_STACK);
-	return TRUE;
-}
-
-MonoBoolean
-ves_icall_System_Threading_ThreadPool_SetMaxThreads (gint workerThreads, gint completionPortThreads)
-{
-	gint min_threads;
-	gint min_io_threads;
-	gint cpu_count;
-
-	cpu_count = mono_cpu_count ();
-	min_threads = async_tp.min_threads;
-	if (workerThreads < min_threads || workerThreads < cpu_count)
-		return FALSE;
-
-	/* We don't really have the concept of completion ports. Do we care here? */
-	min_io_threads = async_io_tp.min_threads;
-	if (completionPortThreads < min_io_threads || completionPortThreads < cpu_count)
-		return FALSE;
-
-	InterlockedExchange (&async_tp.max_threads, workerThreads);
-	InterlockedExchange (&async_io_tp.max_threads, completionPortThreads);
-	return TRUE;
-}
-
-/**
- * mono_install_threadpool_thread_hooks
- * @start_func: the function to be called right after a new threadpool thread is created. Can be NULL.
- * @finish_func: the function to be called right before a thredpool thread is exiting. Can be NULL.
- * @user_data: argument passed to @start_func and @finish_func.
- *
- * @start_fun will be called right after a threadpool thread is created and @finish_func right before a threadpool thread exits.
- * The calls will be made from the thread itself.
- */
-void
-mono_install_threadpool_thread_hooks (MonoThreadPoolFunc start_func, MonoThreadPoolFunc finish_func, gpointer user_data)
-{
-	tp_start_func = start_func;
-	tp_finish_func = finish_func;
-	tp_hooks_user_data = user_data;
-}
-
-/**
- * mono_install_threadpool_item_hooks
- * @begin_func: the function to be called before a threadpool work item processing starts.
- * @end_func: the function to be called after a threadpool work item is finished.
- * @user_data: argument passed to @begin_func and @end_func.
- *
- * The calls will be made from the thread itself and from the same AppDomain
- * where the work item was executed.
- *
- */
-void
-mono_install_threadpool_item_hooks (MonoThreadPoolItemFunc begin_func, MonoThreadPoolItemFunc end_func, gpointer user_data)
-{
-	tp_item_begin_func = begin_func;
-	tp_item_end_func = end_func;
-	tp_item_user_data = user_data;
-}
-
-void
-mono_internal_thread_unhandled_exception (MonoObject* exc)
-{
-	if (mono_runtime_unhandled_exception_policy_get () == MONO_UNHANDLED_POLICY_CURRENT) {
-		gboolean unloaded;
-		MonoClass *klass;
-
-		klass = exc->vtable->klass;
-		unloaded = is_appdomainunloaded_exception (exc->vtable->domain, klass);
-		if (!unloaded && klass != mono_defaults.threadabortexception_class) {
-			mono_unhandled_exception (exc);
-			if (mono_environment_exitcode_get () == 1)
-				exit (255);
-		}
-		if (klass == mono_defaults.threadabortexception_class)
-		 mono_thread_internal_reset_abort (mono_thread_internal_current ());
-	}
-}
-
-/*
- * Suspend creation of new threads.
- */
-void
-mono_thread_pool_suspend (void)
-{
-	if (use_ms_threadpool ()) {
-		mono_threadpool_ms_suspend ();
-		return;
-	}
-	suspended = TRUE;
-}
-
-/*
- * Resume creation of new threads.
- */
-void
-mono_thread_pool_resume (void)
-{
-	if (use_ms_threadpool ()) {
-		mono_threadpool_ms_resume ();
-		return;
-	}
-	suspended = FALSE;
-}

+ 0 - 55
mono/metadata/threadpool.h

@@ -1,55 +0,0 @@
-#ifndef _MONO_THREADPOOL_H_
-#define _MONO_THREADPOOL_H_
-
-#include <mono/metadata/object-internals.h>
-#include <mono/metadata/reflection.h>
-#include <mono/metadata/socket-io.h>
-
-/* No managed code here */
-void mono_thread_pool_init (void);
-void mono_thread_pool_init_tls (void);
-
-void icall_append_job (MonoObject *ar);
-void icall_append_io_job (MonoObject *target, MonoSocketAsyncResult *state);
-
-MonoAsyncResult *
-mono_thread_pool_begin_invoke (MonoDomain *domain, MonoObject *target, MonoMethod *method, gpointer *params);
-
-MonoObject *
-mono_thread_pool_end_invoke (MonoAsyncResult *ares, MonoArray **out_args, MonoObject **exc);
-
-void mono_thread_pool_cleanup (void);
-
-gboolean mono_thread_pool_remove_domain_jobs (MonoDomain *domain, int timeout);
-
-void mono_thread_pool_suspend (void);
-void mono_thread_pool_resume (void);
-
-void
-ves_icall_System_Threading_ThreadPool_GetAvailableThreads (int *workerThreads,
-							   int *completionPortThreads);
-
-void
-ves_icall_System_Threading_ThreadPool_GetMaxThreads (int *workerThreads,
-						     int *completionPortThreads);
-
-void
-ves_icall_System_Threading_ThreadPool_GetMinThreads (gint *workerThreads, 
-								gint *completionPortThreads);
-
-MonoBoolean
-ves_icall_System_Threading_ThreadPool_SetMinThreads (gint workerThreads, 
-								gint completionPortThreads);
-
-MonoBoolean
-ves_icall_System_Threading_ThreadPool_SetMaxThreads (gint workerThreads, 
-								gint completionPortThreads);
-
-typedef void  (*MonoThreadPoolFunc) (gpointer user_data);
-MONO_API void mono_install_threadpool_thread_hooks (MonoThreadPoolFunc start_func, MonoThreadPoolFunc finish_func, gpointer user_data);
-
-typedef void  (*MonoThreadPoolItemFunc) (gpointer user_data);
-MONO_API void mono_install_threadpool_item_hooks (MonoThreadPoolItemFunc begin_func, MonoThreadPoolItemFunc end_func, gpointer user_data);
-
-#endif
-

+ 4 - 0
mono/metadata/threads-types.h

@@ -188,12 +188,16 @@ void ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoApp
 
 MonoInternalThread *mono_thread_internal_current (void);
 
+void mono_thread_internal_check_for_interruption_critical (MonoInternalThread *thread);
+
 void mono_thread_internal_stop (MonoInternalThread *thread);
 
 gboolean mono_thread_internal_has_appdomain_ref (MonoInternalThread *thread, MonoDomain *domain);
 
 void mono_thread_internal_reset_abort (MonoInternalThread *thread);
 
+void mono_thread_internal_unhandled_exception (MonoObject* exc);
+
 void mono_alloc_special_static_data_free (GHashTable *special_static_fields);
 void mono_thread_current_check_pending_interrupt (void);
 

+ 40 - 1
mono/metadata/threads.c

@@ -20,7 +20,6 @@
 #include <mono/metadata/domain-internals.h>
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/threads.h>
-#include <mono/metadata/threadpool.h>
 #include <mono/metadata/threads-types.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/environment.h>
@@ -4655,3 +4654,43 @@ mono_thread_join (gpointer tid)
 	pthread_join (thread, NULL);
 #endif
 }
+
+void
+mono_thread_internal_check_for_interruption_critical (MonoInternalThread *thread)
+{
+	if ((thread->state & (ThreadState_StopRequested | ThreadState_SuspendRequested)) != 0)
+		mono_thread_interruption_checkpoint ();
+}
+
+static inline gboolean
+is_appdomainunloaded_exception (MonoClass *klass)
+{
+	static MonoClass *app_domain_unloaded_exception_klass = NULL;
+
+	if (!app_domain_unloaded_exception_klass)
+		app_domain_unloaded_exception_klass = mono_class_from_name (mono_defaults.corlib, "System", "AppDomainUnloadedException");
+	g_assert (app_domain_unloaded_exception_klass);
+
+	return klass == app_domain_unloaded_exception_klass;
+}
+
+static inline gboolean
+is_threadabort_exception (MonoClass *klass)
+{
+	return klass == mono_defaults.threadabortexception_class;
+}
+
+void
+mono_thread_internal_unhandled_exception (MonoObject* exc)
+{
+	if (mono_runtime_unhandled_exception_policy_get () == MONO_UNHANDLED_POLICY_CURRENT) {
+		MonoClass *klass = exc->vtable->klass;
+		if (is_threadabort_exception (klass)) {
+			mono_thread_internal_reset_abort (mono_thread_internal_current ());
+		} else if (!is_appdomainunloaded_exception (klass)) {
+			mono_unhandled_exception (exc);
+			if (mono_environment_exitcode_get () == 1)
+				exit (255);
+		}
+	}
+}

+ 0 - 184
mono/metadata/tpool-epoll.c

@@ -1,184 +0,0 @@
-/*
- * tpool-epoll.c: epoll related stuff
- *
- * Authors:
- *   Dietmar Maurer ([email protected])
- *   Gonzalo Paniagua Javier ([email protected])
- *
- * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
- * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
- * Copyright 2011 Xamarin Inc (http://www.xamarin.com)
- */
-
-struct _tp_epoll_data {
-	int epollfd;
-};
-
-typedef struct _tp_epoll_data tp_epoll_data;
-static void tp_epoll_modify (gpointer p, int fd, int operation, int events, gboolean is_new);
-static void tp_epoll_shutdown (gpointer event_data);
-static void tp_epoll_wait (gpointer event_data);
-
-static gpointer
-tp_epoll_init (SocketIOData *data)
-{
-	tp_epoll_data *result;
-
-	result = g_new0 (tp_epoll_data, 1);
-#ifdef EPOLL_CLOEXEC
-	result->epollfd = epoll_create1 (EPOLL_CLOEXEC);
-#else
-	result->epollfd = epoll_create (256); /* The number does not really matter */
-	fcntl (result->epollfd, F_SETFD, FD_CLOEXEC);
-#endif
-	if (result->epollfd == -1) {
-		int err = errno;
-		if (g_getenv ("MONO_DEBUG")) {
-#ifdef EPOLL_CLOEXEC
-			g_message ("epoll_create1(EPOLL_CLOEXEC) failed: %d %s", err, g_strerror (err));
-#else
-			g_message ("epoll_create(256) failed: %d %s", err, g_strerror (err));
-#endif
-		}
-
-		return NULL;
-	}
-
-	data->shutdown = tp_epoll_shutdown;
-	data->modify = tp_epoll_modify;
-	data->wait = tp_epoll_wait;
-	return result;
-}
-
-static void
-tp_epoll_modify (gpointer p, int fd, int operation, int events, gboolean is_new)
-{
-	SocketIOData *socket_io_data;
-	tp_epoll_data *data;
-	struct epoll_event evt;
-	int epoll_op;
-
-	socket_io_data = p;
-	data = socket_io_data->event_data;
-
-	memset (&evt, 0, sizeof (evt));
-	evt.data.fd = fd;
-	if ((events & MONO_POLLIN) != 0)
-		evt.events |= EPOLLIN;
-	if ((events & MONO_POLLOUT) != 0)
-		evt.events |= EPOLLOUT;
-
-	epoll_op = (is_new) ? EPOLL_CTL_ADD : EPOLL_CTL_MOD;
-	if (epoll_ctl (data->epollfd, epoll_op, fd, &evt) == -1) {
-		int err = errno;
-		if (epoll_op == EPOLL_CTL_ADD && err == EEXIST) {
-			epoll_op = EPOLL_CTL_MOD;
-			if (epoll_ctl (data->epollfd, epoll_op, fd, &evt) == -1) {
-				g_message ("epoll_ctl(MOD): %d %s", err, g_strerror (err));
-			}
-		}
-	}
-	mono_mutex_unlock (&socket_io_data->io_lock);
-}
-
-static void
-tp_epoll_shutdown (gpointer event_data)
-{
-	tp_epoll_data *data = event_data;
-
-	close (data->epollfd);
-	g_free (data);
-}
-
-#define EPOLL_ERRORS (EPOLLERR | EPOLLHUP)
-#define EPOLL_NEVENTS	128
-static void
-tp_epoll_wait (gpointer p)
-{
-	SocketIOData *socket_io_data;
-	int epollfd;
-	struct epoll_event *events, *evt;
-	int ready = 0, i;
-	gpointer async_results [EPOLL_NEVENTS * 2]; // * 2 because each loop can add up to 2 results here
-	gint nresults;
-	tp_epoll_data *data;
-
-	socket_io_data = p;
-	data = socket_io_data->event_data;
-	epollfd = data->epollfd;
-	events = g_new0 (struct epoll_event, EPOLL_NEVENTS);
-
-	while (1) {
-		mono_gc_set_skip_thread (TRUE);
-
-		do {
-			if (ready == -1) {
-				check_for_interruption_critical ();
-			}
-			ready = epoll_wait (epollfd, events, EPOLL_NEVENTS, -1);
-		} while (ready == -1 && errno == EINTR);
-
-		mono_gc_set_skip_thread (FALSE);
-
-		if (ready == -1) {
-			int err = errno;
-			g_free (events);
-			if (err != EBADF)
-				g_warning ("epoll_wait: %d %s", err, g_strerror (err));
-
-			return;
-		}
-
-		mono_mutex_lock (&socket_io_data->io_lock);
-		if (socket_io_data->inited == 3) {
-			g_free (events);
-			mono_mutex_unlock (&socket_io_data->io_lock);
-			return; /* cleanup called */
-		}
-
-		nresults = 0;
-		for (i = 0; i < ready; i++) {
-			int fd;
-			MonoMList *list;
-			MonoObject *ares;
-
-			evt = &events [i];
-			fd = evt->data.fd;
-			list = mono_g_hash_table_lookup (socket_io_data->sock_to_state, GINT_TO_POINTER (fd));
-			if (list != NULL && (evt->events & (EPOLLIN | EPOLL_ERRORS)) != 0) {
-				ares = get_io_event (&list, MONO_POLLIN);
-				if (ares != NULL)
-					async_results [nresults++] = ares;
-			}
-
-			if (list != NULL && (evt->events & (EPOLLOUT | EPOLL_ERRORS)) != 0) {
-				ares = get_io_event (&list, MONO_POLLOUT);
-				if (ares != NULL)
-					async_results [nresults++] = ares;
-			}
-
-			if (list != NULL) {
-				int p;
-
-				mono_g_hash_table_replace (socket_io_data->sock_to_state, GINT_TO_POINTER (fd), list);
-				p = get_events_from_list (list);
-				evt->events = (p & MONO_POLLOUT) ? EPOLLOUT : 0;
-				evt->events |= (p & MONO_POLLIN) ? EPOLLIN : 0;
-				if (epoll_ctl (epollfd, EPOLL_CTL_MOD, fd, evt) == -1) {
-					if (epoll_ctl (epollfd, EPOLL_CTL_ADD, fd, evt) == -1) {
-						int err = errno;
-						g_message ("epoll(ADD): %d %s", err, g_strerror (err));
-					}
-				}
-			} else {
-				mono_g_hash_table_remove (socket_io_data->sock_to_state, GINT_TO_POINTER (fd));
-				epoll_ctl (epollfd, EPOLL_CTL_DEL, fd, evt);
-			}
-		}
-		mono_mutex_unlock (&socket_io_data->io_lock);
-		threadpool_append_jobs (&async_io_tp, (MonoObject **) async_results, nresults);
-		mono_gc_bzero_aligned (async_results, sizeof (gpointer) * nresults);
-	}
-}
-#undef EPOLL_NEVENTS
-#undef EPOLL_ERRORS

+ 0 - 164
mono/metadata/tpool-kqueue.c

@@ -1,164 +0,0 @@
-/*
- * tpool-kqueue.c: kqueue related stuff
- *
- * Authors:
- *   Gonzalo Paniagua Javier ([email protected])
- *
- * Copyright 2011 Novell, Inc (http://www.novell.com)
- */
-
-struct _tp_kqueue_data {
-	int fd;
-};
-
-typedef struct _tp_kqueue_data tp_kqueue_data;
-static void tp_kqueue_modify (gpointer p, int fd, int operation, int events, gboolean is_new);
-static void tp_kqueue_shutdown (gpointer event_data);
-static void tp_kqueue_wait (gpointer event_data);
-
-static gpointer
-tp_kqueue_init (SocketIOData *data)
-{
-	tp_kqueue_data *result;
-
-	result = g_new0 (tp_kqueue_data, 1);
-	result->fd = kqueue ();
-	if (result->fd == -1)
-		return NULL;
-
-	data->shutdown = tp_kqueue_shutdown;
-	data->modify = tp_kqueue_modify;
-	data->wait = tp_kqueue_wait;
-	return result;
-}
-
-static void
-kevent_change (int kfd, struct kevent *evt, const char *error_str)
-{
-	if (kevent (kfd, evt, 1, NULL, 0, NULL) == -1) {
-		int err = errno;
-		g_message ("kqueue(%s): %d %s", error_str, err, g_strerror (err));
-	}
-}
-
-static void
-tp_kqueue_modify (gpointer p, int fd, int operation, int events, gboolean is_new)
-{
-	SocketIOData *socket_io_data;
-	socket_io_data = p;
-	tp_kqueue_data *data = socket_io_data->event_data;
-	struct kevent evt;
-
-	memset (&evt, 0, sizeof (evt));
-	if ((events & MONO_POLLIN) != 0) {
-		EV_SET (&evt, fd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, 0);
-		kevent_change (data->fd, &evt, "ADD read");
-	}
-
-	if ((events & MONO_POLLOUT) != 0) {
-		EV_SET (&evt, fd, EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, 0);
-		kevent_change (data->fd, &evt, "ADD write");
-	}
-	mono_mutex_unlock (&socket_io_data->io_lock);
-}
-
-static void
-tp_kqueue_shutdown (gpointer event_data)
-{
-	tp_kqueue_data *data = event_data;
-
-	close (data->fd);
-	g_free (data);
-}
-
-#define KQUEUE_NEVENTS	128
-static void
-tp_kqueue_wait (gpointer p)
-{
-	SocketIOData *socket_io_data;
-	int kfd;
-	struct kevent *events, *evt;
-	int ready = 0, i;
-	gpointer async_results [KQUEUE_NEVENTS * 2]; // * 2 because each loop can add up to 2 results here
-	gint nresults;
-	tp_kqueue_data *data;
-
-	socket_io_data = p;
-	data = socket_io_data->event_data;
-	kfd = data->fd;
-	events = g_new0 (struct kevent, KQUEUE_NEVENTS);
-
-	while (1) {
-	
-		mono_gc_set_skip_thread (TRUE);
-
-		do {
-			if (ready == -1) {
-				check_for_interruption_critical ();
-			}
-			ready = kevent (kfd, NULL, 0, events, KQUEUE_NEVENTS, NULL);
-		} while (ready == -1 && errno == EINTR);
-
-		mono_gc_set_skip_thread (FALSE);
-
-		if (ready == -1) {
-			int err = errno;
-			g_free (events);
-			if (err != EBADF)
-				g_warning ("kevent wait: %d %s", err, g_strerror (err));
-
-			return;
-		}
-
-		mono_mutex_lock (&socket_io_data->io_lock);
-		if (socket_io_data->inited == 3) {
-			g_free (events);
-			mono_mutex_unlock (&socket_io_data->io_lock);
-			return; /* cleanup called */
-		}
-
-		nresults = 0;
-		for (i = 0; i < ready; i++) {
-			int fd;
-			MonoMList *list;
-			MonoObject *ares;
-
-			evt = &events [i];
-			fd = evt->ident;
-			list = mono_g_hash_table_lookup (socket_io_data->sock_to_state, GINT_TO_POINTER (fd));
-			if (list != NULL && (evt->filter == EVFILT_READ || (evt->flags & EV_ERROR) != 0)) {
-				ares = get_io_event (&list, MONO_POLLIN);
-				if (ares != NULL)
-					async_results [nresults++] = ares;
-			}
-			if (list != NULL && (evt->filter == EVFILT_WRITE || (evt->flags & EV_ERROR) != 0)) {
-				ares = get_io_event (&list, MONO_POLLOUT);
-				if (ares != NULL)
-					async_results [nresults++] = ares;
-			}
-
-			if (list != NULL) {
-				int p;
-
-				mono_g_hash_table_replace (socket_io_data->sock_to_state, GINT_TO_POINTER (fd), list);
-				p = get_events_from_list (list);
-				if (evt->filter == EVFILT_READ && (p & MONO_POLLIN) != 0) {
-					EV_SET (evt, fd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, 0);
-					kevent_change (kfd, evt, "READD read");
-				}
-
-				if (evt->filter == EVFILT_WRITE && (p & MONO_POLLOUT) != 0) {
-					EV_SET (evt, fd, EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, 0);
-					kevent_change (kfd, evt, "READD write");
-				}
-			} else {
-				mono_g_hash_table_remove (socket_io_data->sock_to_state, GINT_TO_POINTER (fd));
-			}
-		}
-		mono_mutex_unlock (&socket_io_data->io_lock);
-		threadpool_append_jobs (&async_io_tp, (MonoObject **) async_results, nresults);
-		mono_gc_bzero_aligned (async_results, sizeof (gpointer) * nresults);
-	}
-}
-#undef KQUEUE_NEVENTS
-

+ 0 - 333
mono/metadata/tpool-poll.c

@@ -1,333 +0,0 @@
-/*
- * tpool-poll.c: poll related stuff
- *
- * Authors:
- *   Dietmar Maurer ([email protected])
- *   Gonzalo Paniagua Javier ([email protected])
- *
- * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
- * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
- */
-#include <config.h>
-#include <glib.h>
-#include <errno.h>
-
-#include <mono/metadata/mono-ptr-array.h>
-#include <mono/metadata/threadpool.h>
-#include <mono/metadata/threadpool-internals.h>
-#include <mono/utils/mono-semaphore.h>
-#include <mono/utils/mono-poll.h>
-
-#define INIT_POLLFD(a, b, c) {(a)->fd = b; (a)->events = c; (a)->revents = 0;}
-struct _tp_poll_data {
-	int pipe [2];
-	MonoSemType new_sem;
-	mono_pollfd newpfd;
-};
-
-typedef struct _tp_poll_data tp_poll_data;
-
-static void tp_poll_shutdown (gpointer event_data);
-static void tp_poll_modify (gpointer p, int fd, int operation, int events, gboolean is_new);
-static void tp_poll_wait (gpointer p);
-
-gpointer tp_poll_init (SocketIOData *data);
-
-gpointer
-tp_poll_init (SocketIOData *data)
-{
-	tp_poll_data *result;
-#ifdef HOST_WIN32
-	struct sockaddr_in client;
-	struct sockaddr_in server;
-	SOCKET srv;
-	int len;
-#endif
-
-	result = g_new0 (tp_poll_data, 1);
-#ifndef HOST_WIN32
-	if (pipe (result->pipe) != 0) {
-		int err = errno;
-		perror ("mono");
-		g_assert (err);
-	}
-#else
-	srv = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
-	g_assert (srv != INVALID_SOCKET);
-	result->pipe [1] = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
-	g_assert (result->pipe [1] != INVALID_SOCKET);
-
-	server.sin_family = AF_INET;
-	server.sin_addr.s_addr = inet_addr ("127.0.0.1");
-	server.sin_port = 0;
-	if (bind (srv, (SOCKADDR *) &server, sizeof (struct sockaddr_in))) {
-		g_print ("%d\n", WSAGetLastError ());
-		g_assert (1 != 0);
-	}
-
-	len = sizeof (server);
-	getsockname (srv, (SOCKADDR *) &server, &len);
-	listen (srv, 1);
-	if (connect ((SOCKET) result->pipe [1], (SOCKADDR *) &server, sizeof (server)) == SOCKET_ERROR) {
-		g_print ("%d\n", WSAGetLastError ());
-		g_assert (1 != 0);
-	}
-	len = sizeof (client);
-	result->pipe [0] = accept (srv, (SOCKADDR *) &client, &len);
-	g_assert (result->pipe [0] != INVALID_SOCKET);
-	closesocket (srv);
-#endif
-	MONO_SEM_INIT (&result->new_sem, 1);
-	data->shutdown = tp_poll_shutdown;
-	data->modify = tp_poll_modify;
-	data->wait = tp_poll_wait;
-	return result;
-}
-
-static void
-tp_poll_modify (gpointer p, int fd, int operation, int events, gboolean is_new)
-{
-	SocketIOData *socket_io_data;
-	tp_poll_data *data;
-	char msg [1];
-	int unused G_GNUC_UNUSED;
-
-	socket_io_data = p;
-	data = socket_io_data->event_data;
-
-	mono_mutex_unlock (&socket_io_data->io_lock);
-	
-	MONO_SEM_WAIT (&data->new_sem);
-	INIT_POLLFD (&data->newpfd, GPOINTER_TO_INT (fd), events);
-	*msg = (char) operation;
-#ifndef HOST_WIN32
-	unused = write (data->pipe [1], msg, 1);
-#else
-	unused = send ((SOCKET) data->pipe [1], msg, 1, 0);
-#endif
-}
-
-static void
-tp_poll_shutdown (gpointer event_data)
-{
-	tp_poll_data *data = event_data;
-
-#ifdef HOST_WIN32
-	closesocket (data->pipe [0]);
-	closesocket (data->pipe [1]);
-#else
-	if (data->pipe [0] > -1)
-		close (data->pipe [0]);
-	if (data->pipe [1] > -1)
-		close (data->pipe [1]);
-#endif
-	data->pipe [0] = -1;
-	data->pipe [1] = -1;
-	MONO_SEM_DESTROY (&data->new_sem);
-}
-
-static int
-mark_bad_fds (mono_pollfd *pfds, int nfds)
-{
-	int i, ret;
-	mono_pollfd *pfd;
-	int count = 0;
-
-	for (i = 0; i < nfds; i++) {
-		pfd = &pfds [i];
-		if (pfd->fd == -1)
-			continue;
-
-		ret = mono_poll (pfd, 1, 0);
-		if (ret == -1 && errno == EBADF) {
-			pfd->revents |= MONO_POLLNVAL;
-			count++;
-		} else if (ret == 1) {
-			count++;
-		}
-	}
-
-	return count;
-}
-
-static void
-tp_poll_wait (gpointer p)
-{
-#if MONO_SMALL_CONFIG
-#define INITIAL_POLLFD_SIZE	128
-#else
-#define INITIAL_POLLFD_SIZE	1024
-#endif
-#define POLL_ERRORS (MONO_POLLERR | MONO_POLLHUP | MONO_POLLNVAL)
-
-#ifdef DISABLE_SOCKETS
-#define socket_io_cleanup(x)
-#endif
-	mono_pollfd *pfds;
-	gint maxfd = 1;
-	gint allocated;
-	gint i;
-	tp_poll_data *data;
-	SocketIOData *socket_io_data = p;
-	MonoPtrArray async_results;
-	gint nresults;
-
-	data = socket_io_data->event_data;
-	allocated = INITIAL_POLLFD_SIZE;
-	pfds = g_new0 (mono_pollfd, allocated);
-	mono_ptr_array_init (async_results, allocated * 2);
-	INIT_POLLFD (pfds, data->pipe [0], MONO_POLLIN);
-	for (i = 1; i < allocated; i++)
-		INIT_POLLFD (&pfds [i], -1, 0);
-
-	while (1) {
-		int nsock = 0;
-		mono_pollfd *pfd;
-		char one [1];
-		MonoMList *list;
-		MonoObject *ares;
-
-		mono_gc_set_skip_thread (TRUE);
-
-		do {
-			if (nsock == -1) {
-				check_for_interruption_critical ();
-			}
-
-			nsock = mono_poll (pfds, maxfd, -1);
-		} while (nsock == -1 && errno == EINTR);
-
-		mono_gc_set_skip_thread (FALSE);
-
-		/* 
-		 * Apart from EINTR, we only check EBADF, for the rest:
-		 *  EINVAL: mono_poll() 'protects' us from descriptor
-		 *      numbers above the limit if using select() by marking
-		 *      then as MONO_POLLERR.  If a system poll() is being
-		 *      used, the number of descriptor we're passing will not
-		 *      be over sysconf(_SC_OPEN_MAX), as the error would have
-		 *      happened when opening.
-		 *
-		 *  EFAULT: we own the memory pointed by pfds.
-		 *  ENOMEM: we're doomed anyway
-		 *
-		 */
-
-		if (nsock == -1 && errno == EBADF) {
-			pfds->revents = 0; /* Just in case... */
-			nsock = mark_bad_fds (pfds, maxfd);
-		}
-
-		if ((pfds->revents & POLL_ERRORS) != 0) {
-			/* We're supposed to die now, as the pipe has been closed */
-			g_free (pfds);
-			mono_ptr_array_destroy (async_results);
-			socket_io_cleanup (socket_io_data);
-			return;
-		}
-
-		/* Got a new socket */
-		if ((pfds->revents & MONO_POLLIN) != 0) {
-			int nread;
-			gboolean found = FALSE;
-
-			for (i = 1; i < allocated; i++) {
-				pfd = &pfds [i];
-				if (pfd->fd == data->newpfd.fd) {
-					found = TRUE;
-					break;
-				}
-			}
-
-			if (!found) {
-				for (i = 1; i < allocated; i++) {
-					pfd = &pfds [i];
-					if (pfd->fd == -1)
-						break;
-				}
-			}
-
-			if (i == allocated) {
-				mono_pollfd *oldfd;
-
-				oldfd = pfds;
-				i = allocated;
-				allocated = allocated * 2;
-				pfds = g_renew (mono_pollfd, oldfd, allocated);
-				g_free (oldfd);
-				for (; i < allocated; i++)
-					INIT_POLLFD (&pfds [i], -1, 0);
-				//async_results = g_renew (gpointer, async_results, allocated * 2);
-			}
-#ifndef HOST_WIN32
-			nread = read (data->pipe [0], one, 1);
-#else
-			nread = recv ((SOCKET) data->pipe [0], one, 1, 0);
-#endif
-			if (nread <= 0) {
-				g_free (pfds);
-				mono_ptr_array_destroy (async_results);
-				return; /* we're closed */
-			}
-
-			INIT_POLLFD (&pfds [i], data->newpfd.fd, data->newpfd.events);
-			memset (&data->newpfd, 0, sizeof (mono_pollfd));
-			MONO_SEM_POST (&data->new_sem);
-			if (i >= maxfd)
-				maxfd = i + 1;
-			nsock--;
-		}
-
-		if (nsock == 0)
-			continue;
-
-		mono_mutex_lock (&socket_io_data->io_lock);
-		if (socket_io_data->inited == 3) {
-			g_free (pfds);
-			mono_ptr_array_destroy (async_results);
-			mono_mutex_unlock (&socket_io_data->io_lock);
-			return; /* cleanup called */
-		}
-
-		nresults = 0;
-		mono_ptr_array_clear (async_results);
-
-		for (i = 1; i < maxfd && nsock > 0; i++) {
-			pfd = &pfds [i];
-			if (pfd->fd == -1 || pfd->revents == 0)
-				continue;
-
-			nsock--;
-			list = mono_g_hash_table_lookup (socket_io_data->sock_to_state, GINT_TO_POINTER (pfd->fd));
-			if (list != NULL && (pfd->revents & (MONO_POLLIN | POLL_ERRORS)) != 0) {
-				ares = get_io_event (&list, MONO_POLLIN);
-				if (ares != NULL) {
-					mono_ptr_array_append (async_results, ares);
-					++nresults;
-				}
-			}
-
-			if (list != NULL && (pfd->revents & (MONO_POLLOUT | POLL_ERRORS)) != 0) {
-				ares = get_io_event (&list, MONO_POLLOUT);
-				if (ares != NULL) {
-					mono_ptr_array_append (async_results, ares);
-					++nresults;
-				}
-			}
-
-			if (list != NULL) {
-				mono_g_hash_table_replace (socket_io_data->sock_to_state, GINT_TO_POINTER (pfd->fd), list);
-				pfd->events = get_events_from_list (list);
-			} else {
-				mono_g_hash_table_remove (socket_io_data->sock_to_state, GINT_TO_POINTER (pfd->fd));
-				pfd->fd = -1;
-				if (i == maxfd - 1)
-					maxfd--;
-			}
-		}
-		mono_mutex_unlock (&socket_io_data->io_lock);
-		threadpool_append_async_io_jobs ((MonoObject **) async_results.data, nresults);
-		mono_ptr_array_clear (async_results);
-	}
-}
-

+ 3 - 3
mono/mini/debugger-agent.c

@@ -57,10 +57,10 @@
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/environment.h>
 #include <mono/metadata/threads-types.h>
+#include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/socket-io.h>
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/runtime.h>
-#include <mono/metadata/threadpool.h>
 #include <mono/metadata/verify-internals.h>
 #include <mono/utils/mono-semaphore.h>
 #include <mono/utils/mono-error-internals.h>
@@ -2764,7 +2764,7 @@ suspend_vm (void)
 		/*
 		 * Suspend creation of new threadpool threads, since they cannot run
 		 */
-		mono_thread_pool_suspend ();
+		mono_threadpool_ms_suspend ();
 
 	mono_loader_unlock ();
 }
@@ -2807,7 +2807,7 @@ resume_vm (void)
 	//g_assert (err == 0);
 
 	if (suspend_count == 0)
-		mono_thread_pool_resume ();
+		mono_threadpool_ms_resume ();
 
 	mono_loader_unlock ();
 }