} WapiThreadPriority;
gpointer wapi_create_thread_handle (void);
-void wapi_thread_handle_set_exited (gpointer handle, guint32 exitstatus);
void wapi_ref_thread_handle (gpointer handle);
gpointer wapi_get_current_thread_handle (void);
return lookup_thread (handle);
}
-void
-wapi_thread_handle_set_exited (gpointer handle, guint32 exitstatus)
-{
- MonoW32HandleThread *thread_handle;
- int i, thr_ret;
- pid_t pid = wapi_getpid ();
- pthread_t tid = pthread_self ();
-
- if (mono_w32handle_issignalled (handle) ||
- mono_w32handle_get_type (handle) == MONO_W32HANDLE_UNUSED) {
- /* We must have already deliberately finished with
- * this thread, so don't do any more now
- */
- return;
- }
-
- MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Thread %p terminating", __func__, handle);
-
- thread_handle = lookup_thread (handle);
-
- MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Thread %p abandoning held mutexes", __func__, handle);
-
- for (i = 0; i < thread_handle->owned_mutexes->len; i++) {
- gpointer mutex = g_ptr_array_index (thread_handle->owned_mutexes, i);
-
- wapi_mutex_abandon (mutex, pid, tid);
- wapi_thread_disown_mutex (mutex);
- }
- g_ptr_array_free (thread_handle->owned_mutexes, TRUE);
-
- thr_ret = mono_w32handle_lock_handle (handle);
- g_assert (thr_ret == 0);
-
- mono_w32handle_set_signal_state (handle, TRUE, TRUE);
-
- thr_ret = mono_w32handle_unlock_handle (handle);
- g_assert (thr_ret == 0);
-
- MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Recording thread handle %p id %ld status as %d",
- __func__, handle, thread_handle->id, exitstatus);
-
- /* The thread is no longer active, so unref it */
- mono_w32handle_unref (handle);
-}
-
/*
* wapi_create_thread_handle:
*
void mono_thread_cleanup (void)
{
-#if !defined(HOST_WIN32) && !defined(RUN_IN_SUBTHREAD)
- MonoThreadInfo *info;
-
+#if !defined(RUN_IN_SUBTHREAD)
/* The main thread must abandon any held mutexes (particularly
* important for named mutexes as they are shared across
* processes, see bug 74680.) This will happen when the
* thread exits, but if it's not running in a subthread it
* won't exit in time.
*/
- info = mono_thread_info_current ();
- wapi_thread_handle_set_exited (info->handle, mono_environment_exitcode_get ());
+ mono_thread_info_set_exited (mono_thread_info_current ());
#endif
#if 0
#include <mono/utils/mono-threads-posix-signals.h>
#include <mono/utils/mono-coop-semaphore.h>
#include <mono/metadata/gc-internals.h>
+#include <mono/utils/w32handle.h>
#include <errno.h>
nacl_shutdown_gc_thread();
#endif
- wapi_thread_handle_set_exited (current->handle, exit_code);
+ mono_threads_platform_set_exited (current);
mono_thread_info_detach ();
mono_threads_platform_unregister (MonoThreadInfo *info)
{
if (info->handle) {
- wapi_thread_handle_set_exited (info->handle, 0);
+ mono_threads_platform_set_exited (info);
info->handle = NULL;
}
}
#endif
}
+void
+mono_threads_platform_set_exited (MonoThreadInfo *info)
+{
+ MonoW32HandleThread *thread_data;
+ gpointer mutex_handle;
+ int i, thr_ret;
+ pid_t pid;
+ pthread_t tid;
+
+ if (!info->handle || mono_w32handle_issignalled (info->handle) || mono_w32handle_get_type (info->handle) == MONO_W32HANDLE_UNUSED) {
+ /* We must have already deliberately finished
+ * with this thread, so don't do any more now */
+ return;
+ }
+
+ if (!mono_w32handle_lookup (info->handle, MONO_W32HANDLE_THREAD, (gpointer*) &thread_data))
+ g_error ("unknown thread handle %p", info->handle);
+
+ pid = wapi_getpid ();
+ tid = pthread_self ();
+
+ for (i = 0; i < thread_data->owned_mutexes->len; i++) {
+ mutex_handle = g_ptr_array_index (thread_data->owned_mutexes, i);
+ wapi_mutex_abandon (mutex_handle, pid, tid);
+ wapi_thread_disown_mutex (mutex_handle);
+ }
+
+ g_ptr_array_free (thread_data->owned_mutexes, TRUE);
+
+ thr_ret = mono_w32handle_lock_handle (info->handle);
+ g_assert (thr_ret == 0);
+
+ mono_w32handle_set_signal_state (info->handle, TRUE, TRUE);
+
+ thr_ret = mono_w32handle_unlock_handle (info->handle);
+ g_assert (thr_ret == 0);
+
+ /* The thread is no longer active, so unref it */
+ mono_w32handle_unref (info->handle);
+
+ info->handle = NULL;
+}
+
#endif /* defined(_POSIX_VERSION) || defined(__native_client__) */
#if defined(USE_POSIX_BACKEND)
#if defined (PLATFORM_ANDROID)
info->native_handle = gettid ();
#endif
+
+ g_assert (!info->handle);
+ info->handle = wapi_create_thread_handle ();
}
void
#endif
}
+void
+mono_threads_platform_set_exited (MonoThreadInfo *info)
+{
+}
+
#endif
{
return mono_thread_info_get_tid (info) == mono_native_thread_id_get ();
}
+
+void
+mono_thread_info_set_exited (THREAD_INFO_TYPE *info)
+{
+ g_assert (mono_thread_info_is_current (info));
+ mono_threads_platform_set_exited (info);
+}
HANDLE
mono_thread_info_open_handle (void);
+void
+mono_thread_info_set_exited (THREAD_INFO_TYPE *info);
+
void
mono_thread_info_install_interrupt (void (*callback) (gpointer data), gpointer data, gboolean *interrupted);
void mono_threads_platform_unregister (THREAD_INFO_TYPE *info);
HANDLE mono_threads_platform_open_handle (void);
HANDLE mono_threads_platform_open_thread_handle (HANDLE handle, MonoNativeThreadId tid);
+void mono_threads_platform_set_exited (THREAD_INFO_TYPE *info);
void mono_threads_coop_begin_global_suspend (void);
void mono_threads_coop_end_global_suspend (void);