#define _WIN32_WINNT 0x0500
#endif
-#include <mono/metadata/appdomain.h>
+#include <mono/metadata/domain-internals.h>
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/threads.h>
+#include <mono/metadata/threads-types.h>
#include <mono/metadata/exception.h>
#include <mono/metadata/file-io.h>
#include <mono/metadata/monitor.h>
/* maximum number of worker threads */
int mono_max_worker_threads = 25; /* fixme: should be 25 per available CPU */
-int mono_min_worker_threads = 0;
+static int mono_min_worker_threads = 0;
/* current number of worker threads */
static int mono_worker_threads = 0;
/* current number of busy threads */
-int busy_worker_threads = 0;
+static int busy_worker_threads = 0;
/* we use this to store a reference to the AsyncResult to avoid GC */
static MonoGHashTable *ares_htable = NULL;
}
/* notify listeners */
- if(!mono_monitor_try_enter ((MonoObject *) ares, INFINITE))
+ if(!mono_monitor_enter ((MonoObject *) ares))
return;
if (ares->handle != NULL) {
ares->async_delegate = target;
if (!ares_htable) {
+ MONO_GC_REGISTER_ROOT (ares_htable);
ares_htable = mono_g_hash_table_new (NULL, NULL);
job_added = CreateSemaphore (NULL, 0, 0x7fffffff, NULL);
}
*out_args = NULL;
/* check if already finished */
- if (!mono_monitor_try_enter ((MonoObject *) ares, INFINITE)) {
+ if (!mono_monitor_enter ((MonoObject *) ares)) {
return NULL;
}
if (!data) {
guint32 wr;
- wr = WaitForSingleObjectEx (job_added, 500, TRUE);
- mono_thread_interruption_checkpoint ();
-
- if (wr != WAIT_TIMEOUT)
- data = dequeue_job ();
+ int timeout = 500;
+ guint32 start_time = GetTickCount ();
+
+ do {
+ wr = WaitForSingleObjectEx (job_added, (guint32)timeout, TRUE);
+ mono_thread_interruption_checkpoint ();
+
+ timeout -= GetTickCount () - start_time;
+
+ if (wr != WAIT_TIMEOUT)
+ data = dequeue_job ();
+ }
+ while (!data && timeout > 0);
}
if (!data) {
*completionPortThreads = 0;
}
-void
+MonoBoolean
ves_icall_System_Threading_ThreadPool_SetMinThreads (gint workerThreads, gint completionPortThreads)
{
MONO_ARCH_SAVE_REGS;
+ if (workerThreads < 0 || workerThreads > mono_max_worker_threads)
+ return FALSE;
InterlockedExchange (&mono_min_worker_threads, workerThreads);
+ /* FIXME: should actually start the idle threads if needed */
+ return TRUE;
}
static void