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;
}
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;
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];
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*
}
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);