X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Futils%2Fmono-threads-posix.c;h=cb218f5c14d3d3e88957435fb7c5b6d1c5aea175;hb=722f24df519f5abc7287354cb4c1d322d11df2af;hp=0111d5fd9086a939033748796442d08902d2a8d6;hpb=7c4fb8caf0fb90251ec20cf135a3eba293090ee2;p=mono.git diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index 0111d5fd908..cb218f5c14d 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -41,6 +41,7 @@ typedef struct { void *(*start_routine)(void*); void *arg; int flags; + gint32 priority; MonoCoopSem registered; HANDLE handle; } StartInfo; @@ -60,8 +61,7 @@ inner_start_thread (void *arg) /* Register the thread with the io-layer */ handle = wapi_create_thread_handle (); if (!handle) { - res = mono_coop_sem_post (&(start_info->registered)); - g_assert (!res); + mono_coop_sem_post (&(start_info->registered)); return NULL; } start_info->handle = handle; @@ -71,14 +71,15 @@ inner_start_thread (void *arg) info->runtime_thread = TRUE; info->handle = handle; + wapi_init_thread_info_priority(handle, start_info->priority); + if (flags & CREATE_SUSPENDED) { info->create_suspended = TRUE; mono_coop_sem_init (&info->create_suspended_sem, 0); } /* start_info is not valid after this */ - res = mono_coop_sem_post (&(start_info->registered)); - g_assert (!res); + mono_coop_sem_post (&(start_info->registered)); start_info = NULL; if (flags & CREATE_SUSPENDED) { @@ -96,17 +97,20 @@ inner_start_thread (void *arg) } HANDLE -mono_threads_core_create_thread (LPTHREAD_START_ROUTINE start_routine, gpointer arg, guint32 stack_size, guint32 creation_flags, MonoNativeThreadId *out_tid) +mono_threads_core_create_thread (LPTHREAD_START_ROUTINE start_routine, gpointer arg, MonoThreadParm *tp, MonoNativeThreadId *out_tid) { pthread_attr_t attr; int res; pthread_t thread; StartInfo start_info; + guint32 stack_size; + int policy; + struct sched_param sp; res = pthread_attr_init (&attr); g_assert (!res); - if (stack_size == 0) { + if (tp->stack_size == 0) { #if HAVE_VALGRIND_MEMCHECK_H if (RUNNING_ON_VALGRIND) stack_size = 1 << 20; @@ -115,7 +119,8 @@ mono_threads_core_create_thread (LPTHREAD_START_ROUTINE start_routine, gpointer #else stack_size = (SIZEOF_VOID_P / 4) * 1024 * 1024; #endif - } + } else + stack_size = tp->stack_size; #ifdef PTHREAD_STACK_MIN if (stack_size < PTHREAD_STACK_MIN) @@ -127,10 +132,20 @@ mono_threads_core_create_thread (LPTHREAD_START_ROUTINE start_routine, gpointer g_assert (!res); #endif + /* + * For policies that respect priorities set the prirority for the new thread + */ + pthread_getschedparam(pthread_self(), &policy, &sp); + if ((policy == SCHED_FIFO) || (policy == SCHED_RR)) { + sp.sched_priority = wapi_thread_priority_to_posix_priority (tp->priority, policy); + res = pthread_attr_setschedparam (&attr, &sp); + } + memset (&start_info, 0, sizeof (StartInfo)); start_info.start_routine = (void *(*)(void *)) start_routine; start_info.arg = arg; - start_info.flags = creation_flags; + start_info.flags = tp->creation_flags; + start_info.priority = tp->priority; mono_coop_sem_init (&(start_info.registered), 0); /* Actually start the thread */