예제 #1
0
/*
 * mono_threads_create_thread:
 *
 *   Create a new thread executing START with argument ARG. Store its id into OUT_TID.
 * Returns: a windows or io-layer handle for the thread.
 */
MonoThreadHandle*
mono_threads_create_thread (MonoThreadStart start, gpointer arg, gsize * const stack_size, MonoNativeThreadId *out_tid)
{
	CreateThreadData *thread_data;
	gint res;
	MonoThreadHandle *ret;

	thread_data = g_new0 (CreateThreadData, 1);
	mono_refcount_init (thread_data, create_thread_data_destroy);
	thread_data->start_routine = start;
	thread_data->start_routine_arg = arg;
	mono_coop_sem_init (&thread_data->registered, 0);

	res = mono_threads_platform_create_thread (inner_start_thread, (gpointer) mono_refcount_inc (thread_data), stack_size, out_tid);
	if (res != 0) {
		/* ref is not going to be decremented in inner_start_thread */
		mono_refcount_dec (thread_data);
		ret = NULL;
		goto done;
	}

	res = mono_coop_sem_wait (&thread_data->registered, MONO_SEM_FLAGS_NONE);
	g_assert (res == 0);

	ret = thread_data->handle;
	g_assert (ret);

done:
	mono_refcount_dec (thread_data);

	return ret;
}
예제 #2
0
static gsize WINAPI
inner_start_thread (gpointer data)
{
	CreateThreadData *thread_data;
	MonoThreadInfo *info;
	MonoThreadStart start_routine;
	gpointer start_routine_arg;
	gsize start_routine_res;
	gsize dummy;

	thread_data = (CreateThreadData*) data;
	g_assert (thread_data);

	start_routine = thread_data->start_routine;
	start_routine_arg = thread_data->start_routine_arg;

	info = mono_thread_info_attach (&dummy);
	info->runtime_thread = TRUE;

	thread_data->handle = mono_threads_open_thread_handle (info->handle);

	mono_coop_sem_post (&thread_data->registered);

	mono_refcount_dec (thread_data);

	/* thread_data is not valid anymore */
	thread_data = NULL;

	/* Run the actual main function of the thread */
	start_routine_res = start_routine (start_routine_arg);

	mono_thread_info_exit (start_routine_res);

	g_assert_not_reached ();
}
예제 #3
0
void
mono_threadpool_worker_cleanup (void)
{
	mono_refcount_dec (&worker);
}
예제 #4
0
void
mono_threads_close_thread_handle (MonoThreadHandle *thread_handle)
{
	mono_refcount_dec (thread_handle);
}