//Thread initialization code
-static void mono_threads_unregister_current_thread (MonoThreadInfo *info);
-
static inline void
mono_hazard_pointer_clear_all (MonoThreadHazardPointers *hp, int retain)
{
gpointer gc_unsafe_stackdata;
MonoThreadInfo *info;
int small_id;
+ gboolean result;
info = (MonoThreadInfo *) arg;
g_assert (info);
mono_native_tls_set_value (thread_exited_key, GUINT_TO_POINTER (1));
- mono_threads_platform_unregister (info);
-
/*
* TLS destruction order is not reliable so small_id might be cleaned up
* before us.
*/
if (threads_callbacks.thread_unregister)
threads_callbacks.thread_unregister (info);
- mono_threads_unregister_current_thread (info);
+
+ mono_threads_platform_unregister (info);
+ result = mono_thread_info_remove (info);
+ g_assert (result);
mono_threads_transition_detach (info);
mono_thread_info_suspend_unlock ();
#endif
}
-/**
- * Removes the current thread from the thread list.
- * This must be called from the thread unregister callback and nowhere else.
- * The current thread must be passed as TLS might have already been cleaned up.
-*/
-static void
-mono_threads_unregister_current_thread (MonoThreadInfo *info)
-{
- gboolean result;
- g_assert (mono_thread_info_get_tid (info) == mono_native_thread_id_get ());
- result = mono_thread_info_remove (info);
- g_assert (result);
-}
-
MonoThreadInfo*
mono_thread_info_current_unchecked (void)
{
mono_thread_info_core_resume (MonoThreadInfo *info)
{
gboolean res = FALSE;
- if (info->create_suspended) {
- /* Have to special case this, as the normal suspend/resume pair are racy, they don't work if he resume is received before the suspend */
- info->create_suspended = FALSE;
- mono_coop_sem_post (&info->create_suspended_sem);
- return TRUE;
- }
switch (mono_threads_transition_request_resume (info)) {
case ResumeError:
gint32 ref;
MonoThreadStart start_routine;
gpointer start_routine_arg;
- gboolean create_suspended;
gint32 priority;
MonoCoopSem registered;
- MonoThreadInfo *info;
+ gpointer handle;
} CreateThreadData;
static gsize WINAPI
MonoThreadStart start_routine;
gpointer start_routine_arg;
guint32 start_routine_res;
- gboolean create_suspended;
- gint32 priority;
gsize dummy;
- gint res;
thread_data = (CreateThreadData*) data;
g_assert (thread_data);
start_routine = thread_data->start_routine;
start_routine_arg = thread_data->start_routine_arg;
- create_suspended = thread_data->create_suspended;
- priority = thread_data->priority;
-
info = mono_thread_info_attach (&dummy);
info->runtime_thread = TRUE;
- mono_threads_platform_set_priority (info, priority);
-
- if (create_suspended) {
- info->create_suspended = TRUE;
- mono_coop_sem_init (&info->create_suspended_sem, 0);
- }
-
- thread_data->info = info;
+ thread_data->handle = mono_thread_info_duplicate_handle (info);
mono_coop_sem_post (&thread_data->registered);
/* thread_data is not valid anymore */
thread_data = NULL;
- if (create_suspended) {
- res = mono_coop_sem_wait (&info->create_suspended_sem, MONO_SEM_FLAGS_NONE);
- g_assert (res == 0);
-
- mono_coop_sem_destroy (&info->create_suspended_sem);
- }
-
/* Run the actual main function of the thread */
start_routine_res = start_routine (start_routine_arg);
* Returns: a windows or io-layer handle for the thread.
*/
HANDLE
-mono_threads_create_thread (MonoThreadStart start, gpointer arg, MonoThreadParm *tp, MonoNativeThreadId *out_tid)
+mono_threads_create_thread (MonoThreadStart start, gpointer arg, gsize stack_size, MonoNativeThreadId *out_tid)
{
CreateThreadData *thread_data;
- MonoThreadInfo *info;
gint res;
gpointer ret;
thread_data->ref = 2;
thread_data->start_routine = start;
thread_data->start_routine_arg = arg;
- thread_data->create_suspended = tp->creation_flags & CREATE_SUSPENDED;
- thread_data->priority = tp->priority;
mono_coop_sem_init (&thread_data->registered, 0);
- res = mono_threads_platform_create_thread (inner_start_thread, (gpointer) thread_data, tp->stack_size, out_tid);
+ res = mono_threads_platform_create_thread (inner_start_thread, (gpointer) thread_data, stack_size, out_tid);
if (res != 0) {
/* ref is not going to be decremented in inner_start_thread */
InterlockedDecrement (&thread_data->ref);
res = mono_coop_sem_wait (&thread_data->registered, MONO_SEM_FLAGS_NONE);
g_assert (res == 0);
- info = thread_data->info;
- g_assert (info);
-
- ret = info->handle;
+ ret = thread_data->handle;
g_assert (ret);
done:
*alerted = FALSE;
if (ms != INFINITE)
- end = mono_100ns_ticks () + (ms * 1000 * 10);
+ end = mono_msec_ticks() + ms;
mono_lazy_initialize (&sleep_init, sleep_initialize);
for (;;) {
if (ms != INFINITE) {
- now = mono_100ns_ticks ();
- if (now > end)
+ now = mono_msec_ticks();
+ if (now >= end)
break;
}
}
if (ms != INFINITE)
- mono_coop_cond_timedwait (&sleep_cond, &sleep_mutex, (end - now) / 10 / 1000);
+ mono_coop_cond_timedwait (&sleep_cond, &sleep_mutex, end - now);
else
mono_coop_cond_wait (&sleep_cond, &sleep_mutex);
}
gpointer
-mono_thread_info_get_handle (THREAD_INFO_TYPE *info)
-{
- g_assert (info->handle);
- return info->handle;
-}
-
-void
-mono_thread_info_describe (MonoThreadInfo *info, GString *text)
-{
- mono_threads_platform_describe (info, text);
-}
-
-void
-mono_thread_info_own_mutex (MonoThreadInfo *info, gpointer mutex_handle)
+mono_thread_info_duplicate_handle (MonoThreadInfo *info)
{
- mono_threads_platform_own_mutex (info, mutex_handle);
-}
-
-void
-mono_thread_info_disown_mutex (MonoThreadInfo *info, gpointer mutex_handle)
-{
- mono_threads_platform_disown_mutex (info, mutex_handle);
-}
-
-MonoThreadPriority
-mono_thread_info_get_priority (MonoThreadInfo *info)
-{
- return mono_threads_platform_get_priority (info);
-}
-
-void
-mono_thread_info_set_priority (MonoThreadInfo *info, MonoThreadPriority priority)
-{
- mono_threads_platform_set_priority (info, priority);
+ g_assert (mono_thread_info_is_current (info));
+ return mono_threads_platform_duplicate_handle (info);
}