[coop] Use signals for blocking syscall interrupt
authorLudovic Henry <ludovic@xamarin.com>
Tue, 2 Feb 2016 14:51:46 +0000 (14:51 +0000)
committerLudovic Henry <ludovic@xamarin.com>
Wed, 3 Feb 2016 16:56:19 +0000 (16:56 +0000)
mono/utils/mono-threads-state-machine.c
mono/utils/mono-threads.c
mono/utils/mono-threads.h

index 098e02c7ee32e1a558cd6c103ac6a8a03e70a486..d130a13613de89b78e4ee113cec9bc4806f74c9f 100644 (file)
@@ -202,6 +202,7 @@ Returns one of the following values:
 - AsyncSuspendInitSuspend: Thread suspend requested, async suspend needs to be done.
 - AsyncSuspendAlreadySuspended: Thread already suspended, nothing to do.
 - AsyncSuspendWait: Self suspend in progress, asked it to notify us. Caller must add target to the notification set.
+- AsyncSuspendBlocking: Thread in blocking state
 */
 MonoRequestAsyncSuspendResult
 mono_threads_transition_request_async_suspension (MonoThreadInfo *info)
@@ -241,7 +242,7 @@ retry_state_change:
                if (InterlockedCompareExchange (&info->thread_state, build_thread_state (cur_state, suspend_count + 1), raw_state) != raw_state)
                        goto retry_state_change;
                trace_state_change ("ASYNC_SUSPEND_REQUESTED", info, raw_state, cur_state, 1);
-               return AsyncSuspendAlreadySuspended; //A thread in the blocking state has its state saved so we can treat it as suspended.
+               return AsyncSuspendBlocking; //A thread in the blocking state has its state saved so we can treat it as suspended.
 
 /*
 
index 0e67cd6605386a4fbcef76cb17a51763e404303f..6ffc0093228252c85f08751b2afb9faa1a169184 100644 (file)
@@ -776,6 +776,7 @@ mono_thread_info_begin_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
 {
        switch (mono_threads_transition_request_async_suspension (info)) {
        case AsyncSuspendAlreadySuspended:
+       case AsyncSuspendBlocking:
                return TRUE;
        case AsyncSuspendWait:
                mono_threads_add_to_pending_operation_set (info);
@@ -871,6 +872,14 @@ suspend_sync (MonoNativeThreadId tid, gboolean interrupt_kernel)
                        mono_hazard_pointer_clear (hp, 1);
                        return NULL;
                }
+               break;
+       case AsyncSuspendBlocking:
+               if (interrupt_kernel)
+                       mono_threads_core_abort_syscall (info);
+
+               break;
+       default:
+               g_assert_not_reached ();
        }
 
        //Wait for the pending suspend to finish
index 111146811de55977a4b16717d77eeca992b5b478..707e821d429c62770f91263b9f26812547c6d4ad 100644 (file)
@@ -589,6 +589,7 @@ typedef enum {
        AsyncSuspendAlreadySuspended,
        AsyncSuspendWait,
        AsyncSuspendInitSuspend,
+       AsyncSuspendBlocking,
 } MonoRequestAsyncSuspendResult;
 
 typedef enum {