[threading] Introduce mono_thread_info_is_live and move all thread state testing...
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 2 Feb 2015 16:04:37 +0000 (11:04 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 23 Feb 2015 20:47:17 +0000 (15:47 -0500)
mono/metadata/sgen-gc.c
mono/metadata/sgen-stw.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h

index b9dddd477037dbfb7dec01bc22b1944c10d7bf37..0bb81107f6e183fa0aec37e3e89c80c496238e7d 100644 (file)
@@ -3837,8 +3837,8 @@ scan_thread_data (void *start_nursery, void *end_nursery, gboolean precise, Gray
                        SGEN_LOG (3, "GC disabled for thread %p, range: %p-%p, size: %td", info, info->stack_start, info->stack_end, (char*)info->stack_end - (char*)info->stack_start);
                        continue;
                }
-               if (mono_thread_info_run_state (info) != STATE_RUNNING) {
-                       SGEN_LOG (3, "Skipping non-running thread %p, range: %p-%p, size: %td (state %d)", info, info->stack_start, info->stack_end, (char*)info->stack_end - (char*)info->stack_start, mono_thread_info_run_state (info));
+               if (!mono_thread_info_is_live (info)) {
+                       SGEN_LOG (3, "Skipping non-running thread %p, range: %p-%p, size: %td (state %x)", info, info->stack_start, info->stack_end, (char*)info->stack_end - (char*)info->stack_start, info->info.thread_state);
                        continue;
                }
                SGEN_LOG (3, "Scanning thread %p, range: %p-%p, size: %td, pinned=%zd", info, info->stack_start, info->stack_end, (char*)info->stack_end - (char*)info->stack_start, sgen_get_pinned_count ());
index eb6a50d9726cb6c44a2f6733da86c17ebd931e3e..c89e5d216598d079aac305402ce6ff6ba9a580db 100644 (file)
@@ -119,7 +119,7 @@ restart_threads_until_none_in_managed_allocator (void)
                        gboolean result;
                        if (info->skip || info->gc_disabled)
                                continue;
-                       if (mono_thread_info_run_state (info) == STATE_RUNNING && (!info->stack_start || info->in_critical_region || info->info.inside_critical_region ||
+                       if (mono_thread_info_is_live (info) && (!info->stack_start || info->in_critical_region || info->info.inside_critical_region ||
                                        is_ip_in_managed_allocator (info->stopped_domain, info->stopped_ip))) {
                                binary_protocol_thread_restart ((gpointer)mono_thread_info_get_tid (info));
                                SGEN_LOG (3, "thread %p resumed.", (void*) (size_t) info->info.native_handle);
index b38ec5ef7d1ba15f8bc9e2ccbd7783515a6047c9..02510ab5a5194cf60546bba0da53980e0d3788dd 100644 (file)
@@ -57,6 +57,9 @@ static gboolean mono_threads_inited = FALSE;
 
 static void mono_threads_unregister_current_thread (MonoThreadInfo *info);
 
+#define mono_thread_info_run_state(info) (((MonoThreadInfo*)info)->thread_state & RUN_STATE_MASK)
+#define mono_thread_info_suspend_state(info) (((MonoThreadInfo*)info)->thread_state & SUSPEND_STATE_MASK)
+
 
 static inline void
 mono_hazard_pointer_clear_all (MonoThreadHazardPointers *hp, int retain)
@@ -978,3 +981,13 @@ mono_threads_consume_async_jobs (void)
 
        return InterlockedExchange (&info->service_requests, 0);
 }
+
+
+/**
+ * Return TRUE is the thread is in an usable (suspendable) state
+ */
+gboolean
+mono_thread_info_is_live (MonoThreadInfo *info)
+{
+       return mono_thread_info_run_state (info) == STATE_RUNNING;
+}
index 03dbff849701f2137a966d7f0957e33a531b3edc..0565b71abb2de0fe6d87c30fa4deb48445fb13b2 100644 (file)
@@ -101,9 +101,6 @@ typedef enum {
        MONO_SERVICE_REQUEST_SAMPLE = 1,
 } MonoAsyncJob;
 
-#define mono_thread_info_run_state(info) (((MonoThreadInfo*)info)->thread_state & RUN_STATE_MASK)
-#define mono_thread_info_suspend_state(info) (((MonoThreadInfo*)info)->thread_state & SUSPEND_STATE_MASK)
-
 typedef struct {
        MonoLinkedListSetNode node;
        guint32 small_id; /*Used by hazard pointers */
@@ -339,6 +336,9 @@ mono_thread_info_self_interrupt (void);
 void
 mono_thread_info_clear_interruption (void);
 
+gboolean
+mono_thread_info_is_live (THREAD_INFO_TYPE *info) MONO_INTERNAL;
+
 HANDLE
 mono_threads_create_thread (LPTHREAD_START_ROUTINE start, gpointer arg, guint32 stack_size, guint32 creation_flags, MonoNativeThreadId *out_tid);