Merge pull request #2979 from akoeplinger/tests-simplify
[mono.git] / mono / utils / mono-threads-state-machine.c
index 949eb4d63dec551cb31c0a666be3e58494357d1f..4b11800c818411a1a6f8b469c0c05e651ea89768 100644 (file)
@@ -455,52 +455,6 @@ STATE_BLOCKING: Async suspend only begins if a transition to async suspend reque
        }
 }
 
-/*
-This the compensatory transition for failed async suspend.
-
-Async suspend can land on a thread as it began cleaning up and is no longer
-functional. This happens as cleanup is a racy process from the async suspend
-perspective. The thread could have cleaned up its domain or jit_tls, for example.
-
-It can only transition the state as left by a sucessfull finish async suspend transition.
-
-*/
-void
-mono_threads_transition_async_suspend_compensation (MonoThreadInfo* info)
-{
-       int raw_state, cur_state, suspend_count;
-
-retry_state_change:
-       UNWRAP_THREAD_STATE (raw_state, cur_state, suspend_count, info);
-       switch (cur_state) {
-
-       case STATE_ASYNC_SUSPENDED:
-               /*
-               Must be one since if a self suspend is in progress the thread should still be async suspendable.
-               If count > 1 and no self suspend is in progress then it means one of the following two.
-               - the thread was previously suspended, which means we should never reach end suspend in the first place.
-               - another suspend happened concurrently, which means the global suspend lock didn't happen.
-               */
-               if (G_UNLIKELY(suspend_count != 1))
-                       g_error ("[%p] suspend_count = %d, but must be 1", mono_thread_info_get_tid (info), suspend_count);
-               if (InterlockedCompareExchange (&info->thread_state, build_thread_state (STATE_RUNNING, suspend_count - 1), raw_state) != raw_state)
-                       goto retry_state_change;
-               trace_state_change ("COMPENSATE_FINISH_ASYNC_SUSPEND", info, raw_state, STATE_RUNNING, -1);
-               break;
-/*
-STATE_RUNNING
-STATE_SELF_SUSPENDED
-STATE_ASYNC_SUSPEND_REQUESTED
-STATE_BLOCKING
-STATE_BLOCKING_AND_SUSPENDED
-STATE_SELF_SUSPEND_REQUESTED: All those are invalid end states of a sucessfull finish async suspend
-*/
-       default:
-               mono_fatal_with_history ("Cannot transition thread %p from %s with COMPENSATE_FINISH_ASYNC_SUSPEND", mono_thread_info_get_tid (info), state_name (cur_state));
-
-       }
-}
-
 /*
 This transitions the thread into a cooperative state where it's assumed to be suspended but can continue.
 
@@ -605,7 +559,7 @@ It returns one of:
 -Ignore: Thread was not in blocking, nothing to do;
 -IgnoreAndPool: Thread was not blocking and there's a pending suspend that needs to be processed;
 -Ok: Blocking state successfully aborted;
--OkAndPool: Blocking state successfully aborted, there's a pending suspend to be processed though
+-Wait: Blocking state successfully aborted, there's a pending suspend to be processed though
 */
 MonoAbortBlockingResult
 mono_threads_transition_abort_blocking (THREAD_INFO_TYPE* info)
@@ -630,10 +584,12 @@ retry_state_change:
                        trace_state_change ("ABORT_BLOCKING", info, raw_state, STATE_RUNNING, 0);
                        return AbortBlockingOk;
                } else {
-                       if (InterlockedCompareExchange (&info->thread_state, build_thread_state (STATE_SELF_SUSPEND_REQUESTED, suspend_count), raw_state) != raw_state)
+                       if (!(suspend_count > 0))
+                               mono_fatal_with_history ("suspend_count = %d, but should be > 0", suspend_count);
+                       if (InterlockedCompareExchange (&info->thread_state, build_thread_state (STATE_BLOCKING_AND_SUSPENDED, suspend_count), raw_state) != raw_state)
                                goto retry_state_change;
-                       trace_state_change ("ABORT_BLOCKING", info, raw_state, STATE_SELF_SUSPEND_REQUESTED, 0);
-                       return AbortBlockingOkAndPool;
+                       trace_state_change ("ABORT_BLOCKING", info, raw_state, STATE_BLOCKING_AND_SUSPENDED, 0);
+                       return AbortBlockingWait;
                }
 /*
 STATE_ASYNC_SUSPENDED: