#include <mono/utils/mono-memory-model.h>
#include <mono/utils/atomic.h>
#include <mono/utils/checked-build.h>
+#include <mono/utils/mono-threads-debug.h>
#include <errno.h>
mono_threads_transition_state_poll (MonoThreadInfo *info)
{
int raw_state, cur_state, suspend_count;
- g_assert (info == mono_thread_info_current ());
+ g_assert (mono_thread_info_is_current (info));
retry_state_change:
UNWRAP_THREAD_STATE (raw_state, cur_state, suspend_count, info);
retry_state_change:
UNWRAP_THREAD_STATE (raw_state, cur_state, suspend_count, info);
switch (cur_state) {
- case STATE_RUNNING: //Blocking was aborted and not properly restored
- case STATE_ASYNC_SUSPEND_REQUESTED: //Blocking was aborted, not properly restored and now there's a pending suspend
- trace_state_change ("DONE_BLOCKING", info, raw_state, cur_state, 0);
- return DoneBlockingAborted;
-
case STATE_BLOCKING:
if (suspend_count == 0) {
if (InterlockedCompareExchange (&info->thread_state, build_thread_state (STATE_RUNNING, suspend_count), raw_state) != raw_state)
}
/*
+STATE_RUNNING: //Blocking was aborted and not properly restored
+STATE_ASYNC_SUSPEND_REQUESTED: //Blocking was aborted, not properly restored and now there's a pending suspend
STATE_ASYNC_SUSPENDED
STATE_SELF_SUSPENDED: Code should not be running while suspended.
STATE_SELF_SUSPEND_REQUESTED: A blocking operation must not be done while trying to self suspend
-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)
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: