X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fthreads.c;h=6f1a34e2dfc46b18eea5a8d7131ff418a934bcba;hb=010fcfb9ecfef1654b415dbb909a01148a89e827;hp=5905b8064d6f065e02080ff979e135a357f79092;hpb=3478b0aa86b50db14d8cd90bf19dae27f5df100b;p=mono.git diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 5905b8064d6..6f1a34e2dfc 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -135,7 +135,7 @@ static StaticDataInfo context_static_info; static MonoGHashTable *threads=NULL; /* List of app context GC handles. - * Added to from ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (). + * Added to from mono_threads_register_app_context (). */ static GHashTable *contexts = NULL; @@ -1003,19 +1003,31 @@ done: return ret; } -void mono_thread_new_init (intptr_t tid, gpointer stack_start, gpointer func) +/** + * mono_thread_new_init: + */ +void +mono_thread_new_init (intptr_t tid, gpointer stack_start, gpointer func) { if (mono_thread_start_cb) { mono_thread_start_cb (tid, stack_start, func); } } -void mono_threads_set_default_stacksize (guint32 stacksize) +/** + * mono_threads_set_default_stacksize: + */ +void +mono_threads_set_default_stacksize (guint32 stacksize) { default_stacksize = stacksize; } -guint32 mono_threads_get_default_stacksize (void) +/** + * mono_threads_get_default_stacksize: + */ +guint32 +mono_threads_get_default_stacksize (void) { return default_stacksize; } @@ -1048,6 +1060,9 @@ mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, Mo return internal; } +/** + * mono_thread_create: + */ void mono_thread_create (MonoDomain *domain, gpointer func, gpointer arg) { @@ -1062,6 +1077,9 @@ mono_thread_create_checked (MonoDomain *domain, gpointer func, gpointer arg, Mon return (NULL != mono_thread_create_internal (domain, func, arg, MONO_THREAD_CREATE_FLAGS_NONE, error)); } +/** + * mono_thread_attach: + */ MonoThread * mono_thread_attach (MonoDomain *domain) { @@ -1263,6 +1281,9 @@ done: */ } +/** + * mono_thread_detach: + */ void mono_thread_detach (MonoThread *thread) { @@ -1270,12 +1291,12 @@ mono_thread_detach (MonoThread *thread) mono_thread_detach_internal (thread->internal_thread); } -/* +/** * mono_thread_detach_if_exiting: * - * Detach the current thread from the runtime if it is exiting, i.e. it is running pthread dtors. + * Detach the current thread from the runtime if it is exiting, i.e. it is running pthread dtors. * This should be used at the end of embedding code which calls into managed code, and which - * can be called from pthread dtors, like dealloc: implementations in objective-c. + * can be called from pthread dtors, like dealloc: implementations in Objective-C. */ mono_bool mono_thread_detach_if_exiting (void) @@ -1305,6 +1326,9 @@ mono_thread_internal_current_is_attached (void) return TRUE; } +/** + * mono_thread_exit: + */ void mono_thread_exit (void) { @@ -1497,10 +1521,9 @@ mono_thread_get_name (MonoInternalThread *this_obj, guint32 *name_len) return res; } -/* +/** * mono_thread_get_name_utf8: - * - * Return the name of the thread in UTF-8. + * \returns the name of the thread in UTF-8. * Return NULL if the thread has no name. * The returned memory is owned by the caller. */ @@ -1523,11 +1546,10 @@ mono_thread_get_name_utf8 (MonoThread *thread) return tname; } -/* +/** * mono_thread_get_managed_id: - * - * Return the Thread.ManagedThreadId value of `thread`. - * Returns -1 if `thread` is NULL. + * \returns the \c Thread.ManagedThreadId value of \p thread. + * Returns \c -1 if \p thread is NULL. */ int32_t mono_thread_get_managed_id (MonoThread *thread) @@ -1692,6 +1714,9 @@ ves_icall_System_Threading_Thread_ByteArrayToCurrentDomain (MonoArray *arr) return result; } +/** + * mono_thread_current: + */ MonoThread * mono_thread_current (void) { @@ -2620,6 +2645,9 @@ is_running_protected_wrapper (void) return found; } +/** + * mono_thread_stop: + */ void mono_thread_stop (MonoThread *thread) { @@ -2936,8 +2964,9 @@ free_context (void *user_data) } void -ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppContext *ctx) +mono_threads_register_app_context (MonoAppContext *ctx, MonoError *error) { + error_init (error); mono_threads_lock (); //g_print ("Registering context %d in domain %d\n", ctx->context_id, ctx->domain_id); @@ -2969,7 +2998,14 @@ ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppConte } void -ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContext *ctx) +ves_icall_System_Runtime_Remoting_Contexts_Context_RegisterContext (MonoAppContextHandle ctx, MonoError *error) +{ + error_init (error); + mono_threads_register_app_context (MONO_HANDLE_RAW (ctx), error); /* FIXME use handles in mono_threads_register_app_context */ +} + +void +mono_threads_release_app_context (MonoAppContext* ctx, MonoError *error) { /* * NOTE: Since finalizers are unreliable for the purposes of ensuring @@ -2982,6 +3018,13 @@ ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContex mono_profiler_context_unloaded (ctx); } +void +ves_icall_System_Runtime_Remoting_Contexts_Context_ReleaseContext (MonoAppContextHandle ctx, MonoError *error) +{ + error_init (error); + mono_threads_release_app_context (MONO_HANDLE_RAW (ctx), error); /* FIXME use handles in mono_threads_release_app_context */ +} + void mono_thread_init (MonoThreadStartCB start_cb, MonoThreadAttachCB attach_cb) { @@ -2999,7 +3042,11 @@ void mono_thread_init (MonoThreadStartCB start_cb, mono_thread_attach_cb = attach_cb; } -void mono_thread_cleanup (void) +/** + * mono_thread_cleanup: + */ +void +mono_thread_cleanup (void) { #if !defined(RUN_IN_SUBTHREAD) && !defined(HOST_WIN32) /* The main thread must abandon any held mutexes (particularly @@ -3030,6 +3077,9 @@ mono_threads_install_cleanup (MonoThreadCleanupFunc func) mono_thread_cleanup_fn = func; } +/** + * mono_thread_set_manage_callback: + */ void mono_thread_set_manage_callback (MonoThread *thread, MonoThreadManageCallback func) { @@ -3223,7 +3273,11 @@ mono_threads_set_shutting_down (void) } } -void mono_thread_manage (void) +/** + * mono_thread_manage: + */ +void +mono_thread_manage (void) { struct wait_data wait_data; struct wait_data *wait = &wait_data; @@ -3673,7 +3727,10 @@ mono_threads_get_thread_dump (MonoArray **out_threads, MonoArray **out_stack_fra sf->il_offset = location->il_offset; if (location && location->source_file) { - MONO_OBJECT_SETREF (sf, filename, mono_string_new (domain, location->source_file)); + MonoString *filename = mono_string_new_checked (domain, location->source_file, error); + if (!is_ok (error)) + goto leave; + MONO_OBJECT_SETREF (sf, filename, filename); sf->line = location->row; sf->column = location->column; } @@ -3859,10 +3916,6 @@ collect_appdomain_thread (gpointer key, gpointer value, gpointer user_data) gboolean mono_threads_abort_appdomain_threads (MonoDomain *domain, int timeout) { -#ifdef __native_client__ - return FALSE; -#endif - abort_appdomain_data user_data; gint64 start_time; int orig_timeout = timeout; @@ -4378,14 +4431,17 @@ mono_thread_execute_interruption (void) LOCK_THREAD (thread); /* MonoThread::interruption_requested can only be changed with atomics */ - if (mono_thread_clear_interruption_requested (thread)) { - /* this will consume pending APC calls */ + if (!mono_thread_clear_interruption_requested (thread)) { + UNLOCK_THREAD (thread); + return NULL; + } + + /* this will consume pending APC calls */ #ifdef HOST_WIN32 - WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE); + WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE); #endif - /* Clear the interrupted flag of the thread so it can wait again */ - mono_thread_info_clear_self_interrupt (); - } + /* Clear the interrupted flag of the thread so it can wait again */ + mono_thread_info_clear_self_interrupt (); /* If there's a pending exception and an AbortRequested, the pending exception takes precedence */ if (sys_thread->pending_exception) { @@ -4913,14 +4969,14 @@ mono_thread_internal_suspend_for_shutdown (MonoInternalThread *thread) mono_thread_info_safe_suspend_and_run (thread_get_tid (thread), FALSE, suspend_for_shutdown_critical, NULL); } -/* +/** * mono_thread_is_foreign: - * @thread: the thread to query + * \param thread the thread to query * * This function allows one to determine if a thread was created by the mono runtime and has - * a well defined lifecycle or it's a foreigh one, created by the native environment. + * a well defined lifecycle or it's a foreign one, created by the native environment. * - * Returns: TRUE if @thread was not created by the runtime. + * \returns TRUE if \p thread was not created by the runtime. */ mono_bool mono_thread_is_foreign (MonoThread *thread)