void* mono_threads_try_prepare_blocking (void* stackdata) { MonoThreadInfo *info; if (!mono_threads_is_coop_enabled ()) return NULL; ++coop_try_blocking_count; info = mono_thread_info_current_unchecked (); /* If the thread is not attached, it doesn't make sense prepare for suspend. */ if (!info || !mono_thread_info_is_live (info) || mono_thread_info_current_state (info) == STATE_BLOCKING) { THREADS_SUSPEND_DEBUG ("PREPARE-TRY-BLOCKING failed %p\n", mono_thread_info_get_tid (info)); return NULL; } copy_stack_data (info, stackdata); retry: ++coop_save_count; mono_threads_get_runtime_callbacks ()->thread_state_init (&info->thread_saved_state [SELF_SUSPEND_STATE_INDEX]); switch (mono_threads_transition_do_blocking (info)) { case DoBlockingContinue: break; case DoBlockingPollAndRetry: mono_threads_state_poll (); goto retry; } return info; }
gboolean mono_thread_is_gc_unsafe_mode (void) { MonoThreadInfo *cur = mono_thread_info_current (); if (!cur) return FALSE; switch (mono_thread_info_current_state (cur)) { case STATE_RUNNING: case STATE_ASYNC_SUSPEND_REQUESTED: return TRUE; default: return FALSE; } }
void assert_gc_safe_mode (void) { MonoThreadInfo *cur = mono_thread_info_current (); int state; if (!cur) assertion_fail ("Expected GC Safe mode but thread is not attached"); switch (state = mono_thread_info_current_state (cur)) { case STATE_BLOCKING: case STATE_BLOCKING_AND_SUSPENDED: break; default: assertion_fail ("Expected GC Safe mode but was in %s state", mono_thread_state_name (state)); } }
void assert_gc_unsafe_mode (void) { MonoThreadInfo *cur = mono_thread_info_current (); int state; if (!cur) assertion_fail ("Expected GC Unsafe mode but thread is not attached"); switch (state = mono_thread_info_current_state (cur)) { case STATE_RUNNING: case STATE_ASYNC_SUSPEND_REQUESTED: case STATE_SELF_SUSPEND_REQUESTED: break; default: assertion_fail ("Expected GC Unsafe mode but was in %s state", mono_thread_state_name (state)); } }
void assert_not_in_gc_critical_region(void) { CheckState *state = get_state(); if (state->in_gc_critical_region > 0) { assertion_fail("Expected GC Unsafe mode, but was in %s state", mono_thread_state_name (mono_thread_info_current_state (mono_thread_info_current ()))); } }