X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fsgen%2Fsgen-thread-pool.c;h=c9aaaa2667b5cb9b45cf5b7427f43e8a8bd96060;hb=HEAD;hp=6a03bc3d69d164b5cd949b0b71760fc84f41d04b;hpb=ff285585d451b696333ecb22a729b38acb633bdf;p=mono.git diff --git a/mono/sgen/sgen-thread-pool.c b/mono/sgen/sgen-thread-pool.c index 6a03bc3d69d..c9aaaa2667b 100644 --- a/mono/sgen/sgen-thread-pool.c +++ b/mono/sgen/sgen-thread-pool.c @@ -21,6 +21,7 @@ static mono_cond_t done_cond; static int threads_num; static MonoNativeThreadId threads [SGEN_THREADPOOL_MAX_NUM_THREADS]; +static int threads_context [SGEN_THREADPOOL_MAX_NUM_THREADS]; static volatile gboolean threadpool_shutdown; static volatile int threads_finished; @@ -166,8 +167,9 @@ get_work (int worker_index, int *work_context, int *do_idle, SgenThreadPoolJob * } static mono_native_thread_return_t -thread_func (int worker_index) +thread_func (void *data) { + int worker_index = (int)(gsize)data; int current_context; void *thread_data = NULL; @@ -190,7 +192,9 @@ thread_func (int worker_index) SgenThreadPoolJob *job = NULL; SgenThreadPoolContext *context = NULL; + threads_context [worker_index] = -1; get_work (worker_index, ¤t_context, &do_idle, &job); + threads_context [worker_index] = current_context; if (!threadpool_shutdown) { context = &pool_contexts [current_context]; @@ -301,6 +305,10 @@ sgen_thread_pool_shutdown (void) mono_os_mutex_destroy (&lock); mono_os_cond_destroy (&work_cond); mono_os_cond_destroy (&done_cond); + + for (int i = 0; i < threads_num; i++) { + mono_threads_add_joinable_thread ((gpointer)threads [i]); + } } SgenThreadPoolJob* @@ -358,13 +366,13 @@ sgen_thread_pool_idle_signal (int context_id) } void -sgen_thread_pool_idle_wait (int context_id) +sgen_thread_pool_idle_wait (int context_id, SgenThreadPoolContinueIdleWaitFunc continue_wait) { SGEN_ASSERT (0, pool_contexts [context_id].idle_job_func, "Why are we waiting for idle without an idle function?"); mono_os_mutex_lock (&lock); - while (pool_contexts [context_id].continue_idle_job_func (NULL, context_id)) + while (continue_wait (context_id, threads_context)) mono_os_cond_wait (&done_cond, &lock); mono_os_mutex_unlock (&lock);